From ripley at stats.ox.ac.uk  Tue Aug 24 22:50:38 2010
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue, 24 Aug 2010 21:50:38 +0100 (BST)
Subject: [Rd] require is to suggests as what is to imports?
In-Reply-To: <AANLkTi=EOFdYKP0JUZLCz8r7KRJ1PaYFGQgresAQJ6r1@mail.gmail.com>
References: <AANLkTi=EOFdYKP0JUZLCz8r7KRJ1PaYFGQgresAQJ6r1@mail.gmail.com>
Message-ID: <alpine.LFD.2.00.1008242144540.20682@gannet.stats.ox.ac.uk>

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.

> 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



[Rd] require is to suggests as what is to imports?
Prof Brian Ripley