R语言安装所有扩展包 Install All Packages in CRAN

方案1:获取已安装列表,把CRAN上的包去掉列表然后全部安装
# get names of installed packages
packs <- installed.packages()
exc <- names(packs[,'Package'])
# get available package names
av <- names(available.packages()[,1])
# create loooong string
ins <- av[!av %in% exc]
install.packages(ins)

方案2:同上
availablePackages=available.packages()
availablePackages<-as.vector(availablePackages[,1])
installedPackages=.packages(all.available = TRUE)
missedPackages<-setdiff(availablePackages, installedPackages)
for (i in 1:length(missedPackages))
{
pkgName <- missedPackages[i]
install.packages(pkgName)
}
print("END")
本文采用 CC BY-NC-SA 4.0 创作共享协议,转载请标注以下信息:
【转载自LiuJason's Blog:https://www.liujason.com/article/249.html

说点什么

Please Login to comment
avatar
  Subscribe  
提醒