Yichao: is there an alternative "is_installed" definition that would check the load path? Lets assume I don't actually want to import it, just check.
On Mon, Jun 27, 2016 at 12:48 PM, Yichao Yu <[email protected]> wrote: > > On Jun 27, 2016 12:20 PM, "Tom Breloff" <[email protected]> wrote: > > > > Here is what I use for this sort of logic: > > > > function is_installed(pkgstr::AbstractString) > > try > > Pkg.installed(pkgstr) === nothing ? false: true > > Dont do this since this will miss package in load path. Just eval a using > expression. > > > catch > > false > > end > > end > > > > > > On Mon, Jun 27, 2016 at 12:12 PM, David Anthoff <[email protected]> > wrote: > >> > >> I’m trying to use ``using`` in a try catch block, but that doesn’t seem > to be supported. > >> > >> > >> > >> Any other way around this? Essentially I want to load a package, and if > the package is not installed, automatically do a ``Pkg.add``. > >> > >> > >> > >> I could of course get a list of all the installed packages and see if > the one I need is there, but given the slowness of the package manager, I > would prefer to just try to load it first, and only if that fails attempt > to ``Pkg.add``. > >> > >> > >> > >> Thanks, > >> > >> David > >> > >> > >> > >> -- > >> > >> David Anthoff > >> > >> University of California, Berkeley > >> > >> > >> > >> http://www.david-anthoff.com > >> > >> > > > > >
