自动更新从R-forge安装的软件包

时间:2010-10-19 19:11:00

标签: r r-forge

我最近从R-2.11.1安装了R-2.12.0,我通过以下方式更新了所有CRAN包:

update.packages(checkBuilt=TRUE, ask=FALSE)

现在我想更新我从R-forge安装的所有软件包,但只有在CRAN上不可用时才会更新。换句话说,我不能简单地运行:

update.packages(checkBuilt=TRUE, ask=FALSE, repos="http://r-forge.r-project.org")

因为它会在R-2.12.0附带的版本上安装survival软件包的R-forge版本。

我可能会使用来自old.packagespackageStatus的信息的某种组合来确定哪些软件包仅存在于R-forge上,但我想在构建自定义之前询问是否有更简单的方法溶液

1 个答案:

答案 0 :(得分:47)

这个怎么样:

# 1. Get the list of packages you have installed, 
#    use priority to exclude base and recommended packages.
#    that may have been distributed with R.
pkgList <- installed.packages(priority='NA')[,'Package']

# 2. Find out which packages are on CRAN and R-Forge.  Because
#    of R-Forge build capacity is currently limiting the number of
#    binaries available, it is queried for source packages only.
CRANpkgs <- available.packages(
  contriburl=contrib.url('http://cran.r-project.org'))[,'Package']
forgePkgs <- available.packages(
  contriburl=contrib.url('http://r-forge.r-project.org', type='source')
)[,'Package']

# 3. Calculate the set of packages which are installed on your machine,
#    not on CRAN but also present on R-Force.
pkgsToUp <- intersect(setdiff(pkgList, CRANpkgs), forgePkgs)

# 4. Update the packages, using oldPkgs to restrict the list considered.
update.packages(checkBuilt=TRUE, ask=FALSE,
  repos="http://r-forge.r-project.org",
  oldPkgs=pkgsToUp)

# 5. Profit?