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. Thanks, Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/
Prof Brian Ripley
2010-Aug-24 20:50 UTC
[Rd] require is to suggests as what is to imports?
On Tue, 24 Aug 2010, 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 packageWell, not really as requires() can give an error, at least until 2.12.0 is out. So you need to wrap it in a try/tryCatch construct.> is available without loading it, if you only want to access one > function in the package namespace.You could use try/tryCatch on pkg::fun (which is what you need to do with require). It is difficult (and would be fragile since the details of metadata are definitely subject to change without notice) to ascertain what a namespace will contain/export without loading it.> Thanks, > > Hadley > > -- > Assistant Professor / Dobelman Family Junior Chair > Department of Statistics / Rice University > http://had.co.nz/ > > ______________________________________________ > 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
Dirk Eddelbuettel
2010-Aug-24 20:51 UTC
[Rd] require is to suggests as what is to imports?
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
On Tue, Aug 24, 2010 at 3:50 PM, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:> On Tue, 24 Aug 2010, 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 > > Well, not really as requires() can give an error, at least until 2.12.0 is > out. ?So you need to wrap it in a try/tryCatch construct. > >> is available without loading it, if you only want to access one >> function in the package namespace. > > You could use try/tryCatch on pkg::fun (which is what you need to do with > require). ?It is difficult (and would be fragile since the details of > metadata are definitely subject to change without notice) to ascertain what > a namespace will contain/export without loading it.Ok, thanks. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/