[R] How to specify search order for require()
Frank E Harrell Jr
fharrell at virginia.edu
Fri Apr 12 23:23:27 CEST 2002
Thank you Thomas Lumley and Luke Tierney for your responses. I think in the long run Luke's approach is a good one. For now I decided to be expeditious by redefining library to take a pos= argument. All that's needed is to pass this to the attach( ) inside library, which I hope R-core will add to the library function. I also modified require (calling it requirePos) to implement a pos argument. My usage of these is as follows:
library(Hmisc)
# attaches Hmisc library, redefine library, define requirePos
library(Design, pos=2)
.First.lib in Design:
.First.lib <- function(lib, pkg) {
library.dynam("Design", pkg, lib)
requirePos('Hmisc',pos=2)
requirePos('survival',pos=3)
p <- .packages()
if(match('Design',p) > match('survival',p))
warning('By not specifying library(Design,pos=2), functions in the\nsurvival package such as survfit will override those in Design.')
invisible()
}
I realize that overrides are to be avoided but there are a few I couldn't get around easily. I hope that library and require are enhanced with pos=.
Frank
On Fri, 12 Apr 2002 12:06:31 -0400
Frank E Harrell Jr <fharrell at virginia.edu> 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
>
> --
> Frank E Harrell Jr Prof. of Biostatistics & Statistics
> Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
> U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
--
Frank E Harrell Jr Prof. of Biostatistics & Statistics
Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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