From edd at debian.org  Wed Aug 25 15:27:41 2010
From: edd at debian.org (Dirk Eddelbuettel)
Date: Wed, 25 Aug 2010 08:27:41 -0500
Subject: [Rd] require is to suggests as what is to imports?
In-Reply-To: <alpine.LFD.2.00.1008250749080.28875@gannet.stats.ox.ac.uk>
References: <AANLkTi=EOFdYKP0JUZLCz8r7KRJ1PaYFGQgresAQJ6r1@mail.gmail.com>
	<19572.12499.732450.953347@max.nulle.part>
	<alpine.LFD.2.00.1008250749080.28875@gannet.stats.ox.ac.uk>
Message-ID: <19573.6733.664686.910439@max.nulle.part>


On 25 August 2010 at 08:06, Prof Brian Ripley wrote:
| On Tue, 24 Aug 2010, Dirk Eddelbuettel 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.
| 
| But thereby clobber your users with the run-time cost of 
| installed.packages() (which can take several minutes on some Windows 

Yes. As that was for a so-far internal-only package that in all likelihood
will never be built on Windows for limitations of the latter platform.

Regardless, I will switch to Henrik's elegant alternative.

| systems, and just took ca 12secs on my fastest Linux server with 3000 
| packages installed).  If you want to take this route (is a package 
| installed?), see the 'Note' on ?installed.packages for better 
| alternatives.

My version of ?installed.packages has no section "Note". That is on the on
the current, released version of R.

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com



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