Eva Nordstrom
2010-Aug-20 19:25 UTC
[R] loading a package within R, in a MS Windows environment?
I am using R 2.11.1 in a Microsoft Windows environment. Is there a way to load a package (e.g. the zoo package) using only "written code", not menus or mouse clicks? The "code" below code brings up the "Select One" [package] menu. I just want to automatically load the "zoo package". local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE) + if(nchar(pkg)) library(pkg, character.only=TRUE)}) [[alternative HTML version deleted]]
Duncan Murdoch
2010-Aug-20 19:44 UTC
[R] loading a package within R, in a MS Windows environment?
On 20/08/2010 3:25 PM, Eva Nordstrom wrote:> I am using R 2.11.1 in a Microsoft Windows environment. Is there a way to load a > package (e.g. the zoo package) using only "written code", not menus or mouse > clicks? > > The "code" below code brings up the "Select One" [package] menu. I just want to > automatically load the "zoo package". > > local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE) > + if(nchar(pkg)) library(pkg, character.only=TRUE)})Simply say library(zoo) and it will be loaded, as long as you have it installed. If you don't have it installed that will fail. In that case, first say install.packages("zoo", dependencies=TRUE) This might bring up a menu if you haven't already said which CRAN mirror to use. To avoid that, first you should say mirrors <- getCRANmirrors() mirrors Read the list, pick which one you like, then do options(repos=mirrors[n, "URL"]) where n is the row number of the mirror you want. No menus! Duncan Murdoch
David Winsemius
2010-Aug-20 19:45 UTC
[R] loading a package within R, in a MS Windows environment?
On Aug 20, 2010, at 3:25 PM, Eva Nordstrom wrote:> I am using R 2.11.1 in a Microsoft Windows environment. Is there a > way to load a > package (e.g. the zoo package) using only "written code", not menus > or mouse > clicks? > > The "code" below code brings up the "Select One" [package] menu. I > just want to > automatically load the "zoo package". > > local({pkg <- select.list(sort(.packages(all.available = > TRUE)),graphics=TRUE) > + if(nchar(pkg)) library(pkg, character.only=TRUE)})what's wrong with: require(zoo) #? I suppose you could do something fancier like: stopifnot(require(zoo)) ... but I don't think that adds any benefit. -- David
Erik Iverson
2010-Aug-20 19:46 UTC
[R] loading a package within R, in a MS Windows environment?
Are you just looking for: library(zoo) ? Eva Nordstrom wrote:> I am using R 2.11.1 in a Microsoft Windows environment. Is there a way to load a > package (e.g. the zoo package) using only "written code", not menus or mouse > clicks? > > The "code" below code brings up the "Select One" [package] menu. I just want to > automatically load the "zoo package". > > local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE) > + if(nchar(pkg)) library(pkg, character.only=TRUE)}) > > > > > [[alternative HTML version deleted]] > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.