Windows 7:通过脚本安装多个R包

时间:2012-11-05 23:22:20

标签: r

我试图脚本[R 2.15.1在Windows 7中的次安装R安装就好了,但我无法弄清楚如何从同一个批处理脚本安装多个软件包(或任何批处理脚本,对于这个问题)。下面是我称之为简单R文件的脚本部分。

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

以下是“RME for GME.R”的内容,其中包含要安装的软件包。

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

鉴于documented ownership and ACLs issues with writing to the default library folder in Windows,我尝试了以下内容:

  1. 取得“C:\ Program Files \ R \ R-2.15.1 \ library”的所有权,然后运行R CMD BATCH <file>(无变更);
  2. 在同一文件夹中为我的用户帐户授予“完全控制”权限,然后运行R CMD BATCH <file>(无更改);
  3. 通过Rprofile.site将库文件夹更改为其他位置,然后运行R CMD BATCH <file>(无更改);
  4. 通过Rgui install.packages("CircStats","coda","deldir","gplots","igraph","ks","odesolve","RandomFields",dep=TRUE)(工作)运行命令。
  5. 到目前为止,我没有运气使用CMD或批处理脚本来安装软件包。有什么我想念的吗?任何替代脚本包安装的方法都将非常感激。

    此外,我将安装的机器适用于多个用户,因此首选系统安装和配置。

    //

    编辑2012-11-06: 以下是.Rout文件中的错误消息:

    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
    

    如果我之后执行library(coda),则会提供Error in library(coda) : there is no package called ‘coda’

1 个答案:

答案 0 :(得分:8)

odesolve软件包已弃用,已被deSolve取代。 R 2.15.1遇到此程序包时抛出错误。它可能会给你带来麻烦。这是我用于安装新R安装包的脚本。

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)