最近需要在内网的windows环境下部署R分析平台,内网遇到的最大困就是安装R语言的软件包和对应的依赖包。
第一步 先下载安装包和依赖包
代码语言:text复制Getpackage <- function(packs){
packages <- unlist(
tools::package_dependencies(packs, available.packages(),which = c('Depends','Imports'), recursive =T)
)
packages <- union(packs,packages)
packages
}
mypackages <- c('tidyverse') # 需要安装的包名
packages <- Getpackage(mypackages)
download.packages(packages,destdir = "D:/Downloads/",type = 'win.binary') # 下载包存放目录,D:/Downloads/
第二步 批量安装
将第一步下载的zip压缩包复制到内网环境下,我这里以D:/packages目录为例。
代码语言:text复制# 内网环境下
library(tools)
install.path <- 'D:/packages'
write_PACKAGES(install.path, type='win.binary')
mypackages <- c('tidyverse') # 需要安装的包名
install.packages(mypackages, contriburl = paste('file:',install.path,sep = ''), repos = NULL, type='win.binary')
完美~