When I load an add-on package, is there any way to specify where it ends up in the search path (as with the pos argument to attach())? From the documentation for library(), this doesn't seem like an option. (I know I can detach packages and then reload them in the order I want; I'm looking for a less clumsy way.) Thanks, Jim James A. Rogers, Ph.D. <rogers at cantatapharm.com> Statistical Scientist Cantata Pharmaceuticals 300 Technology Square, 5th floor Cambridge, MA 02139 617.225.9009 x312 Fax 617.225.9010
Specifying search position for attached package
2 messages · Jim Rogers, David Brahm
Jim Rogers <jrogers at cantatapharm.com> wrote:
When I load an add-on package, is there any way to specify where it ends up in the search path (as with the pos argument to attach())? From the documentation for library(), this doesn't seem like an option.
I wrote a local version of library (g.library) which has an additional "pos=2"
argument. It's an exact copy of library except for the one line:
env <- attach(NULL, name = pkgname)
which becomes:
env <- attach(NULL, pos, name=pkgname)
There may be subtle reasons why this could fail (and why it's not part of the
standard library function), but it's always worked just fine for me (in version
1.6.2 on Solaris 2.6; I haven't upgraded to 1.7.0 yet).
I also wrote a g.sync function that allows me to detach and re-attach (in the
same position) a package that has been modified and rebuilt. It boils down to:
g.sync <- function(pos=2) {
pkg <- sub("package:", "", search()[pos])
detach(pos=pos)
g.library(pkg, char=TRUE, pos=pos)
}
-- David Brahm (brahm at alum.mit.edu)