Exploring package contents

Hi I’m getting into Julia and I don’t yet understamd how I can find out what I can type.

For instance I want to read CSV, so I add the CSV package, but then how do I know how to use it? In C# I would either open a NuGet package in the Object Browser to see what classes etc are in there, or I could use intellisense to type the namespace and dot through the namespaces and classes in there. That way I can pretty quickly figure out how to use something.

How am I supposed to do this in Julia? Right now I rely on either the help, a tutorial or I browse the source, but isn’t there a way for Julia to just show all the things that are contained in the package/ module? I feel I’m missing something obvious here.

For instance te CSV package does not have any help defined and intellisense brings up a lot of things but the actual stuff I can use seems mixed up with all sorts of unrelated things.

Reading the documentation of CSV will probably be helpful, if there is documentation. Reading the documentation does not take many minutes and is usually worth the effort.

3 Likes

Obviously, and the CSV package has good docs, but still this makes me rely on the effort (and time) of someone else to describe the functionality. Isn;t there a command like contents(CSV) that lists the methods etc that are defined in a package/ module?

I do wish it were more common that ?CSV would return a brief API summary. For example:

help?> Images
search: Images nimages ImageDistances ImageAxes ImageTransformations ImageContrastAdjustment ImageQualityIndexes ImageMeta ImageCore ImageMetadata ImageFiltering ImageMorphology integral_image

  Constructors, conversions, and traits:

  - Construction: use constructors of specialized packages, e.g., `AxisArray`, `ImageMeta`, etc.
  - "Conversion": `colorview`, `channelview`, `rawview`, `normedview`, `permuteddimsview`
  - Traits: `pixelspacing`, `sdims`, `timeaxis`, `timedim`, `spacedirections`

  Contrast/coloration:

  - `clamp01`, `clamp01nan`, `scaleminmax`, `colorsigned`, `scalesigned`

  Algorithms:

  - Reductions: `maxfinite`, `maxabsfinite`, `minfinite`, `meanfinite`, `integral_image`, `boxdiff`, `gaussian_pyramid`
  - Resizing: `restrict`, `imresize` (not yet exported)
  - Filtering: `imfilter`, `imfilter!`, `mapwindow`, `imROF`, `padarray`
  - Filtering kernels: `Kernel.` or `KernelFactors.`, followed by `ando[345]`, `guassian2d`, `imaverage`, `imdog`, `imlaplacian`, `prewitt`, `sobel`
  - Exposure : `imhist`, `histeq`, `adjust_gamma`, `histmatch`, `imadjustintensity`, `imstretch`, `imcomplement`, `clahe`, `cliphist`
  - Gradients: `backdiffx`, `backdiffy`, `forwarddiffx`, `forwarddiffy`, `imgradients`
  - Edge detection: `imedge`, `imgradients`, `thin_edges`, `magnitude`, `phase`, `magnitudephase`, `orientation`, `canny`
  - Corner detection: `imcorner`,`imcorner_subpixel`, `harris`, `shi_tomasi`, `kitchen_rosenfeld`, `meancovs`, `gammacovs`, `fastcorners`
  - Blob detection: `blob_LoG`, `findlocalmaxima`, `findlocalminima`
  - Morphological operations: `dilate`, `erode`, `closing`, `opening`, `tophat`, `bothat`, `morphogradient`, `morpholaplace`, `feature_transform`, `distance_transform`, `convexhull`
  - Connected components: `label_components`, `component_boxes`, `component_lengths`, `component_indices`, `component_subscripts`, `component_centroids`
  - Interpolation: `bilinear_interpolation`

  Test images and phantoms (see also TestImages.jl):

  - `shepp_logan`

But there isn’t a good way of keeping these in sync, so it requires that one do this manually.

You can use using Example; names(Example) to determine the exported names, but for packages like CSV that expect module-scoping you need names(CVS; all=true).

6 Likes

At least one can avoid repetition by including this in the docs, eg as done in

https://tkf.github.io/ThreadsX.jl/dev/

Ok

show(names(CSV, all=true))

helped already indeed. At some point you can see where the methods start. But still it should possible for Julia with the introspection features to neatly display the contents of somehtig right, this just hasn;t been written yet?

It’s not hard to write, but distinguishing methods intended to be called by users from internal methods is not straightforward. For example,

julia> using MethodAnalysis

julia> mths = Method[]


julia> visit(Images) do item
           isa(item, Method) && (push!(mths, item); return false)
           return true
       end

yields 4664 methods in mths. Most of these are not interesting from the standpoint of users.

2 Likes

Can I see which names are explicitely exported?

Just leave out the all=true from names.

But CSV deliberately doesn’t export its API. This is pretty common when the name used is very generic. We use ForwardDiff.gradient without exporting gradient (because lots of packages implement methods called gradient), Revise.track(stdlib) because track is far too generic on its own, etc.

2 Likes

Ah, I myself keep forgetting about the most useful one:

julia> apropos(CSV)
DelimitedFiles
DelimitedFiles.DelimitedFiles
SharedArrays.SharedArray
Tables.LazyTable
Tables.partitioner
Base.show
CSV
CSV.detect
CSV.RowWriter
CSV.File
CSV.write
CSV.PooledString
CSV.Rows
CSV.read
CSV.Chunks
FileIO.DataFormat

This at least shows you all the things that have “CSV” in their documentation.

10 Likes