[R] How to specify search order for require()

Thomas Lumley tlumley at u.washington.edu
Fri Apr 12 18:31:00 CEST 2002


On Fri, 12 Apr 2002, Frank E Harrell Jr wrote:

> In a .First.lib I want to issue two require()s to insure that two other
> packages are loaded.  But I want the package being loaded by .First.lib
> using library.dynam("mypackage",pkb,lib) to be higher in the search
> order than the two required packages, because I want to have a couple of
> functions from the two required packages overridden.  What is the best
> way to do that?  Thanks in advance -Frank

This would really need library() and require() to take a pos= argument (I
don't see why they shouldn't, but given the current feature freeze it's
not happening right now).

A work-around is to define two packages, say,
"mypackage" and "my.actual.package" and bundle them together.

.First.lib in "mypackage" would require() the two additional packages and
then require() "my.actual.package".

.First.lib in "my.actual.package" would check that the required packages
(and "mypackage") had been loaded, and otherwise give an error telling the
user to use library(mypackage) instead of library(my.actual.package).

As one of the comments in the R source code says in a different context,
this is the sort of thing that gives horrible hacks a bad name, but it
should work.

	-thomas


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list