[Rd] require is to suggests as what is to imports?

Henrik Bengtsson hb at stat.berkeley.edu
Wed Aug 25 01:55:38 CEST 2010


isPackageInstalled <- function(package, ...) {
  path <- system.file(package=package);
  (path != "");
}

taken from R.utils (which also has a isPackageLoaded()).

/Henrik

On Tue, Aug 24, 2010 at 1:51 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
>
> On 24 August 2010 at 15:40, Hadley Wickham wrote:
> | Hi all,
> |
> | If a package suggests another package in its description, you can
> | check it at runtime with requires.  How do you do check if a package
> | is available without loading it, if you only want to access one
> | function in the package namespace.
>
> I needed this a few days ago for a small package and resorted to this:
>
>   .packages <- as.character(installed.packages()[,1])
>
>   [...]
>
>   hasGputools <- function() {
>       any( "gputools" == .packages )
>   }
>
> That way I get around Depends, Suggests and other thing that may impact the
> running of 'R CMD check' and friends.
>
> Dirk
>
> --
> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list