Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 7: Installing multiple R packages via script

Tags:

r

I am trying to script the installation of R 2.15.1 on Windows 7. R installs just fine, but I cannot figure out how to install multiple packages from the same batch script (or any batch script, for that matter). Below is the part of the script where I call a simple R file.

"%ProgramFiles%\R\R-2.15.1\bin\R.exe" CMD BATCH "%~dp0R packages for GME.R"

Here is the contents of "R packages for GME.R" that has the packages to install.

install.packages("CircStats","coda","deldir","gplots","igraph","ks","odesolve","RandomFields",dep=TRUE)

Given documented ownership and ACLs issues with writing to the default library folder in Windows, I've tried the following:

  1. Taking ownership of "C:\Program Files\R\R-2.15.1\library", then running R CMD BATCH <file> (no change);
  2. Giving "Full Control" permissions to my user account on the same folder, then running R CMD BATCH <file> (no change);
  3. Changing the library folder to another location via Rprofile.site, then running R CMD BATCH <file> (no change);
  4. Running command via Rgui install.packages("CircStats","coda","deldir","gplots","igraph","ks","odesolve","RandomFields",dep=TRUE) (works).

So far, I have had no luck using CMD or batch scripts to install packages. Is there something I'm missing? Any alternative ways of scripting package installation would be greatly appreciated.

Also, the machines I will be installing on are for multiple users, so system-wide installations and configurations are preferred.

//

Edit 2012-11-06: Here is the error message from the .Rout file:

install.packages("CircStats","coda","deldir","gplots","igraph","ks","odesolve","RandomFields",dep=TRUE)
Warning in install.packages("CircStats", "coda", "deldir", "gplots", "igraph",  :
  'lib = "coda"' is not writable
Error in install.packages("CircStats", "coda", "deldir", "gplots", "igraph",  : 
  unable to install packages
Execution halted

If I execute library(coda) afterwards, it gives Error in library(coda) : there is no package called ‘coda’.

like image 822
Neal Mann Avatar asked Jan 15 '23 03:01

Neal Mann


1 Answers

The odesolve package is depreciated and has been replaced by deSolve. R 2.15.1 is throwing an error when encountering this package. It could be causing problems for you. Here's a script I use for installing packages for new R installs.

libs=c("CircStats","coda","deldir","gplots","igraph","ks","odesolve‌​","RandomFields")
type=getOption("pkgType")                           
    CheckInstallPackage <- function(packages, repos="http://cran.r-project.org",
       depend=c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances"), ...) {
         installed=as.data.frame(installed.packages())
    for(p in packages) {
        if(is.na(charmatch(p, installed[,1]))) { 
          install.packages(p, repos=repos, dependencies=depend, ...) 
                    }
      }
    } 
    CheckInstallPackage(packages=libs)
like image 187
Jeffrey Evans Avatar answered Jan 18 '23 23:01

Jeffrey Evans