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" == Frank E Harrell, <Frank> writes:frank> In a .First.lib I want to issue two require()s to insure frank> that two other packages are loaded. But I want the package frank> being loaded by .First.lib using frank> library.dynam("mypackage",pkb,lib) to be higher in the frank> search order than the two required packages, because I want frank> to have a couple of functions from the two required frank> packages overridden. What is the best way to do that? frank> Thanks in advance -Frank Good question. If you find out, let me know, too! best, -tony -- A.J. Rossini Rsrch. Asst. Prof. of Biostatistics U. of Washington Biostatistics rossini at u.washington.edu FHCRC/SCHARP/HIV Vaccine Trials Net rossini at scharp.org -------------- http://software.biostat.washington.edu/ ---------------- FHCRC: M-W: 206-667-7025 (fax=4812)|Voicemail is pretty sketchy/use Email UW: Th: 206-543-1044 (fax=3286)|Change last 4 digits of phone to FAX (my friday location is usually completely unpredictable.) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 -FrankThis 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
As of 1.4 (I believe) packages loaded by a require in the package source, as oopsed to .First.lib, are loaded after the package that calls require. This was done in part to allow packages to require(methods) and then use functions defined in methods within the package body. Hopefully R 1.6 will add a name space mechanism that will provide much finer control over package dependencies; some information on how that might work along with a draft implementation is available off the developer page developer.r-project.org or at http://www.stat.umn.edu/~luke/R/namespaces/morenames.html. luke On Fri, Apr 12, 2002 at 12:06:31PM -0400, 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 > > -- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- Luke Tierney University of Minnesota Phone: 612-625-7843 School of Statistics Fax: 612-624-8868 313 Ford Hall, 224 Church St. S.E. email: luke at stat.umn.edu Minneapolis, MN 55455 USA WWW: http://www.stat.umn.edu -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Frank E Harrell Jr <fharrell at virginia.edu> writes:> 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 second that; in fact I've requested it a couple times (most recently in R-devel on 3/28/02). I believe it really is just as simple as passing "pos" to attach(), and I also override the built-in function. -- -- David Brahm (brahm at alum.mit.edu) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._