From hb at stat.berkeley.edu  Wed Aug 25 01:55:38 2010
From: hb at stat.berkeley.edu (Henrik Bengtsson)
Date: Tue, 24 Aug 2010 16:55:38 -0700
Subject: [Rd] require is to suggests as what is to imports?
In-Reply-To: <19572.12499.732450.953347@max.nulle.part>
References: <AANLkTi=EOFdYKP0JUZLCz8r7KRJ1PaYFGQgresAQJ6r1@mail.gmail.com>
	<19572.12499.732450.953347@max.nulle.part>
Message-ID: <AANLkTi=xVsz3z-3mxuFCGUJUDF2sLPjDvEJM3t4G9VWL@mail.gmail.com>

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
>



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