[Rd] require vs library
ripley@stats.ox.ac.uk
ripley@stats.ox.ac.uk
Fri Feb 21 19:07:02 2003
There seems to be a widespread assumption that the way for package foo to
require package bar is via `require(bar)'. It isn't!
That returns a logical which is in the vast majority of cases unchecked.
So if the package is really required, the code will fail without a warning
if the package is unavailable. You may as well call library() and let it
do the checking. (In a few cases you can safely assume that the package
is present, e.g. nnet can require(MASS) since they are installed
together.)
I find it confusing if require(bar, quietly=TRUE) is used with no message.
If you are going to change the search path, please let the end user know
you have done so. I've had nasty surprises more than once from this by
getting datasets from packages I did not ask to be there.
Another point: please do not call code with side effects like require,
library or options at the top level in foo/R/foo, but do so within
.First.lib. This becomes important if the code is dumped or put in a
database.
--
Brian D. Ripley, ripley@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