[R] loading a package within R, in a MS Windows environment?
Duncan Murdoch
murdoch.duncan at gmail.com
Fri Aug 20 21:44:42 CEST 2010
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
More information about the R-help
mailing list