Re: [R] loading precedence in requires()

About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [R] loading precedence in requires()
From: Prof Brian D Ripley (
Date: Mon 08 Nov 1999 - 17:51:47 EST

Message-ID: <Pine.GSO.4.05.9911080727320.7214-100000@auk.stats>

[ Moved to R-devel as it is a think this is a development issue. ]

On Mon, 8 Nov 1999, Ray Brownrigg wrote:

> It appears that requires(), when it appears in the .First.lib of a
> package, will load the required package *after* the package requiring
> it, i.e. the 'required' package appears earlier in the search list than
> the package requiring it.
> This will cause problems if a package (deliberately) masks any of the
> functions in the required package. I.e. the expected masking does not
> occur.
> Apart from expecting the end-user to issue a library() call for the
> required package before the requiring package, are there any
> workarounds for this, or is such deliberate masking considered to be a
> no-no?

At present in R (unlike S) packages are effectively thought of as equal,
and searched in inverse order of loading. Unlike S, library (and hence
require) has no way to set the position in the ordering, nor can a library
`database' be re-attached in a different place in the order by attach().
(The latter is a common trick in .First.lib in S.)

I have two ideas for now:

(a) Write a package foo containing just a .First.lib with


and put the real code in foo2.

(b) in the .First.lib for package foo, use something like

.First.lib <- function (...)
    s <- search()
    if (length(search()) > length(s)) {

In general such masking (presumably of a system library or why not enhance
bar?) is confusing and leads to support difficulties. It is a headache for
S-PLUS where Harrell's Design and Hmisc mask many system functions, and one
gets used to asking: "are you using Design or Hmisc?" if there are reports
of strange behaviour in one's own code. My view has become `only mask if
you wish to correct something, and try to ge the original changed'.

However, question to R-devel: should we add to library and require
argument(s) to say where they should go in the search list? S3 has
first=T (and defaults to last), and S-PLUS 5 has both first=T and pos
(which can be a number or database, and the library is inserted just before
the one specified, and always before main). The most flexible scheme might
be to have both before= and after= for names or numbers.

Ross is planning changes in this area that may make the re-attach idea
feasible in R.

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Tue 04 Jan 2000 - 14:16:09 EST