Use Package (Add if Needed; Using)

Is it possible to define a function that tests if a package has been installed already, installs it if not yet so, and then invokes using. something like

use(name) = try Pkg.installed(name) catch Pkg.add(name) end; using name

This fails for multiple reasons. It would be even better if this could be a statement rather than a function call, so that

use DataFrames;

would simply work.

Advice appreciated. And apologies: I will have a lot of questions over the next 1-3 weeks, because I plan to use Julia as a first-class language in my MFE class at UCLA. Wish me luck! I am putting together a cookbook at http://julia.cookbook.tips, hopefully understandable in a week or two…

In Pkg3 (the new Julia package manager) it will work like:

you can also set it to automatically install without querying.

11 Likes