[Rd] require is to suggests as what is to imports?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Aug 25 09:06:29 CEST 2010
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
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.
However, that was not the question. require() is most often used to
answer the question 'is this package usable?' which includes checking
that it is installed for the right architecture and has all its
dependencies (recursively). And Hadley's question implies both that a
namespace can be loaded (includind DSO/DLL and dependencies) and that
it contains/exports a specific function.
One thing many package authors have been forgetting is that on Mac OS
X there are several sub-architectures and you need a DSO of the right
architecture to be installed (and the default for R CMD INSTALL has
been to install only one, and on Snow Leopard R and R.app run
different sub-architectures). As from 2.12.x this will apply to
Windows too.
>
> 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
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel
mailing list