R:如何离线安装软件包和依赖项

时间:2018-08-09 14:10:14

标签: r repository libraries offline cran

首先,我知道有关该主题的另一篇文章,但这并不能解决我的问题。

Offline install of R package and dependencies

我需要在脱机的Ubuntu计算机上安装许多软件包,但是依赖关系不断混乱。

首先,我使用以下代码(在在线ubuntu机器上)下载所有软件包和依赖项:

# Loading library
library(tools)

# Function for downloading packages and dependencies
getPackages <- function(packs){
  packages <- unlist(
    tools::package_dependencies(packs, available.packages(),
                                which=c("Depends", "Imports"), recursive=TRUE)
  )
  packages <- union(packs, packages)
  packages
}

# Determining what packages to download
packages <- getPackages(c("tidyverse", "data.table", "RODBC", "RJDBC", "fasttime", "tidyr", "knitr", "randomForest", "RMySQL", "jsonlite"))

# Downloading packages
download.packages(pkgs = packages, destdir = "/path/to/packages/")

# Writing files such that this folder can be used as a repository
write_PACKAGES("/path/to/packages/")

第二,使用链接中的以下命令,将软件包安装在脱机计算机上。

# Installs local packages
install.packages(c("tidyverse", "data.table", "RODBC", "RJDBC", "fasttime", "tidyr", "knitr", "randomForest", "RMySQL", "jsonlite"), contriburl = "file:///path/to/packages/") 

发生的事情是,该安装程序可以在几个软件包上运行,然后崩溃并显示消息。

ERROR: dependency ‘dplyr’ is not available for package ‘tidyr’
* removing ‘/home/h52z/R/x86_64-pc-linux-gnu-library/3.4/tidyr’
ERROR: dependencies ‘dplyr’, ‘tidyr’ are not available for package ‘tidyverse’
* removing ‘/home/h52z/R/x86_64-pc-linux-gnu-library/3.4/tidyverse’
Warning messages:
1: In install.packages(c("tidyverse", "data.table", "RODBC", "RJDBC",  :
  installation of package ‘dplyr’ had non-zero exit status
2: In install.packages(c("tidyverse", "data.table", "RODBC", "RJDBC",  :
  installation of package ‘tidyr’ had non-zero exit status
3: In install.packages(c("tidyverse", "data.table", "RODBC", "RJDBC",  :
  installation of package ‘tidyverse’ had non-zero exit status

尽管使用工具库创建了本地存储库,但安装程序似乎无法处理依赖项。要做很多工作,必须找出自己应该按照什么顺序安装软件包。

您有什么建议吗?我是否必须使用 miniCRAN 之类的工具,还是需要像其他链接中的示例一样下载整个CRAN存储库?

1 个答案:

答案 0 :(得分:1)

我建议使用miniCRAN,特别是pkgDep函数来处理所有依赖项。例如

library(miniCRAN)

pkgs <- c("tidyverse", "data.table", "RODBC", "RJDBC", "fasttime", "tidyr", 
    "knitr", "randomForest", "RMySQL", "jsonlite")
pkgList <- pkgDep(pkgs, type = "source", suggests = FALSE)
makeRepo(pkgList, path="/path/to/packages/", type = c("source"))

然后您将使用以下代码从仓库中安装

install.packages(pkgs, repos="file://path/to/packages/", type="source")