Cookbook: Difference between revisions

Jump to navigation Jump to search
16 bytes removed ,  22 September 2016
→‎Find if a package is installed: use pkg list instead of pkg describe, because describe has an odd behaviour
(→‎Programs, Libraries, and Packages: add recipe to check if package is missing)
(→‎Find if a package is installed: use pkg list instead of pkg describe, because describe has an odd behaviour)
Line 35: Line 35:
==== Solution ====
==== Solution ====


Use {{codeline|pkg ("describe", pkg-name)}} like so:
Use {{codeline|pkg ("list", pkg-name)}} like so:


  if (! isempty (pkg ("describe", "foo")))
  if (! isempty (pkg ("list", "foo")))
   ## use functions from package foo, the prefered way
   ## use functions from package foo, the prefered way
  elseif (! isempty (pkg ("describe", "bar")))
  elseif (! isempty (pkg ("list", "bar")))
   ## use functions from package bar, not so optimal
   ## use functions from package bar, not so optimal
  else
  else
Line 65: Line 65:


  ## Again, doesn't add anything.  The failure of 'pkg load' is enough
  ## Again, doesn't add anything.  The failure of 'pkg load' is enough
  if (isempty (pkg ("describe", "foo")))
  if (isempty (pkg ("list", "foo")))
   error ("program: package foo is not installed");
   error ("program: package foo is not installed");
  endif
  endif

Navigation menu