Hi All, I've been working on updating the 'genetics' package. As a consequence of the upgrade, .First.lib() looks like: .First.lib <- function(libname, pkgname) { if (!require(combinat)) warning("Unable to load 'combinat' library. Function `diseq.ci' will fail.") require(gregmisc) genotype <- get("genotype",pos="package:genetics") } the First.lib of the "gregmisc" package in turn does require("MASS") which defines a data set "genotype" which masks the "genotype" function in my genetics library. Is there any clean way to load libraries in .First.lib while preventing this kind of masking? Ideally, there would be something like require("gregmisc", top=FALSE) which would load the library (and any libraries it loads) into the *third* position rather than the second position of the search path (.GlobalEnv is in the first slot)? Actually, does it make sense in general to have top=FALSE be the default behavior when loading packages from .First.lib to avoid masking of this type? For the moment I'm doing : .First.lib <- function(libname, pkgname) { if (!require(combinat)) warning("Unable to load 'combinat' library. Function `diseq.ci' will fail.") require(gregmisc) assign("genotype", get("genotype",pos="package:genetics"), pos=.GlobalEnv ) } but this is a hack and doesn't solve the general problem. -Greg LEGAL NOTICE\ Unless expressly stated otherwise, this message is... {{dropped}}
I believe recent R-devel has a `pos' argument to library() which lets you attach a package in a certain position. Can't think of anything else though. -roger Warnes, Gregory R wrote:> Hi All, > > I've been working on updating the 'genetics' package. As a consequence of > the upgrade, .First.lib() looks like: > > .First.lib <- function(libname, pkgname) > { > if (!require(combinat)) > warning("Unable to load 'combinat' library. Function > `diseq.ci' will fail.") > require(gregmisc) > genotype <- get("genotype",pos="package:genetics") > } > > the First.lib of the "gregmisc" package in turn does > require("MASS") > which defines a data set "genotype" which masks the "genotype" function in > my genetics library. > > Is there any clean way to load libraries in .First.lib while preventing this > kind of masking? Ideally, there would be something like > > require("gregmisc", top=FALSE) > > which would load the library (and any libraries it loads) into the *third* > position rather than the second position of the search path (.GlobalEnv is > in the first slot)? Actually, does it make sense in general to have > top=FALSE be the default behavior when loading packages from .First.lib to > avoid masking of this type? > > For the moment I'm doing : > > .First.lib <- function(libname, pkgname) > { > if (!require(combinat)) > warning("Unable to load 'combinat' library. Function > `diseq.ci' will fail.") > require(gregmisc) > assign("genotype", get("genotype",pos="package:genetics"), > pos=.GlobalEnv ) > } > > but this is a hack and doesn't solve the general problem. > > -Greg > > > > LEGAL NOTICE\ Unless expressly stated otherwise, this message is... {{dropped}} > > ______________________________________________ > R-devel@stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-devel > >
I just checked, and r-devel does not have a "pos" argument to library() or require(). -G> -----Original Message----- > From: Roger D. Peng [mailto:rpeng@stat.ucla.edu] > Sent: Thursday, May 22, 2003 2:40 PM > To: Warnes, Gregory R > Cc: 'R-devel@stat.math.ethz.ch' > Subject: Re: [Rd] How to avoid function masking > > > I believe recent R-devel has a `pos' argument to library() which lets > you attach a package in a certain position. Can't think of anything > else though. > > -roger > > Warnes, Gregory R wrote: > > Hi All, > > > > I've been working on updating the 'genetics' package. As a > consequence of > > the upgrade, .First.lib() looks like: > > > > .First.lib <- function(libname, pkgname) > > { > > if (!require(combinat)) > > warning("Unable to load 'combinat' library. Function > > `diseq.ci' will fail.") > > require(gregmisc) > > genotype <- get("genotype",pos="package:genetics") > > } > > > > the First.lib of the "gregmisc" package in turn does > > require("MASS") > > which defines a data set "genotype" which masks the > "genotype" function in > > my genetics library. > > > > Is there any clean way to load libraries in .First.lib > while preventing this > > kind of masking? Ideally, there would be something like > > > > require("gregmisc", top=FALSE) > > > > which would load the library (and any libraries it loads) > into the *third* > > position rather than the second position of the search path > (.GlobalEnv is > > in the first slot)? Actually, does it make sense in > general to have > > top=FALSE be the default behavior when loading packages > from .First.lib to > > avoid masking of this type? > > > > For the moment I'm doing : > > > > .First.lib <- function(libname, pkgname) > > { > > if (!require(combinat)) > > warning("Unable to load 'combinat' library. Function > > `diseq.ci' will fail.") > > require(gregmisc) > > assign("genotype", get("genotype",pos="package:genetics"), > > pos=.GlobalEnv ) > > } > > > > but this is a hack and doesn't solve the general problem. > > > > -Greg > > > > > > > > LEGAL NOTICE\ Unless expressly stated otherwise, this > message is... {{dropped}} > > > > ______________________________________________ > > R-devel@stat.math.ethz.ch mailing list > > https://www.stat.math.ethz.ch/mailman/listinfo/r-devel > > > > >LEGAL NOTICE\ Unless expressly stated otherwise, this message is... {{dropped}}
> -----Original Message----- > From: Martin Maechler [mailto:maechler@stat.math.ethz.ch] > Sent: Friday, May 23, 2003 9:00 AM > To: Warnes, Gregory R> You checked wrongly. library() *does* for several days now. > (require doesn't -- on purpose?)Yes, I was wrong. have a typo in my script that calls rsync, and the updates went into a different directory, so the code that I was looking at was actually the released 1.7.0 code. Looking at the new code, it appears that the pos argument only applies the the package explicitly named in library() and not to a any packages it loads. Is this intentional? -G LEGAL NOTICE\ Unless expressly stated otherwise, this message is... {{dropped}}