Howto find documentation?

In python, I can use help(function, module, etc) to get documentation. Even if not documented, I can use dir(object) to discover things about it (e.g., find what’s in a module).

How do I do this with julia?

In the REPL, you can use ?function to get interactive documentation.

2 Likes

This also works in the IJulia (Jupyter) notebook.

1 Like

Both in the REPL and in a script:

@doc function-name

But, really, the best way to discover how to read the documentation is to read the documentation :wink:

5 Likes

As previously mentioned, in the REPL a line starting with ? is a documentation lookup. E.g. ?map will give you documentation about the function map; this also works with types. Interestingly, this also works with packages; you can do ?PackageName to see the readme for installed package PackageName.

Sometimes you don’t know the function you need. Then you can use apropos (not in help mode) to search. For example, maybe I don’t know how to create an identity matrix. apropos("identity") will give a list of functions which may match.

Sometimes you have an object and don’t know what you can do with it. You can try methodswith(typeof(object)) (or just methodswith(T) if T is a type) to see available methods.

4 Likes

Since you also mentioned dir(object), you may also be interested in fieldnames(...) which lists all fields of an object or type:

type MyType
    x::Int
    y::Int
end

fieldnames(MyType)               # called on type ==>  [:x, :y]
fieldnames(MyType(1, 2))         # called on instances ==> [:x, :y]

In case you want to look at actual implementation, you can use @edit macro. For example:

@edit qr(rand(3,3))

will open qr.jl in configured editor and point you to the corresponding lines (if editor support it).

2 Likes

I have had a blog post on this “in the works” for quite awhile. Right now it’s just a huge list of commands, and I want a little bit of a walk through it. Here’s a “public preview”

http://www.stochasticlifestyle.com/?p=96&preview=1&_ppp=8821b19e7b

If anyone wants to help me finish it, just let me know.

2 Likes

There’s also a nice overview by @astrieanna here: Julia Helps | juliabloggers.com


It’s not accessible

Huh, public preview links must reset after a few days.

http://www.stochasticlifestyle.com/?p=96&preview=1&_ppp=9f2c7dab73

Nice list! Seems to be missing “methods”.

thanks, preview link’s been expired again. This is a replicate of ChrisRackauckas’s original post.