The help page for library says that: package, help: name or character string giving the name of a package. Yet, I don't seem to be able to use a string variable here.> version_ platform sparc-sun-solaris2.6 arch sparc os solaris2.6 system sparc, solaris2.6 status major 1 minor 3.1 year 2001 month 08 day 31 language R> pkg <- "ts" > pkg[1] "ts"> library(pkg)Error in library(pkg) : There is no package called `pkg'> library(ts) > detach(2) > library("ts") >What am I misunderstanding? Why isn't pkg treated the same as "ts" by library()? Thanks, Dave Kane -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dave Kane <a296180 at onyx.fmr.com> (my next-door neighbor) wrote:> R> pkg <- "ts" > R> library(pkg) > Error in library(pkg) : There is no package called `pkg'You need: R> library(pkg, character.only=TRUE) -- -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"David Kane <David Kane" <a296180 at mica.fmr.com> writes:> > pkg <- "ts" > > pkg > [1] "ts" > > library(pkg) > Error in library(pkg) : There is no package called `pkg' > > library(ts) > > detach(2) > > library("ts") > > > > What am I misunderstanding? Why isn't pkg treated the same as "ts" by library()?Welcome to the world of nonstandard argument evaluation... Similar issues relate to the argument to help et al. Basically, we have been trying to be nice to the user and allow them to "forget" putting quotes around the package name. As a consequence, library(pkg) might also have been intended to load someones "prototype kernel generator" or so, and there's really no way to tell. As David B. points out there is a way to override this. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 seen in Dave Kane's question and my response, one needs the "character.only" argument to library() in order to make a loop like this work: R> for (i in rlibs) library(i, character.only=TRUE) It seems like a similar option would be useful for detach(): R> for (i in rlibs) detach(paste("package",i,sep=":")) # FAILS! and any other functions which immediately run substitute() on their arguments. -- -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._