R语言中如何批量安装R包
1、
> library(qqman) ## 未安装的包 Error in library(qqman) : 不存在叫‘qqman’这个名字的程辑包 > library(data.table) Error in library(data.table) : 不存在叫‘data.table’这个名字的程辑包 > library(detectRUNS) Error in library(detectRUNS) : 不存在叫‘detectRUNS’这个名字的程辑包 > candidate_pak <- c("qqman", "data.table", "detectRUNS") ## 生成包向量 > candidate_pak [1] "qqman" "data.table" "detectRUNS" > install.packages(candidate_pak) ## 批量安装包
批量加载:
> candidate_pak [1] "qqman" "data.table" "detectRUNS" > for (i in candidate_pak) { ## 利用for循环批量加载 + library(i, character.only = T) + }
2、判断包是否提前安装
> candidate_pak <- c("qqman", "data.table", "detectRUNS") > candidate_pak [1] "qqman" "data.table" "detectRUNS" > candidate_pak %in% installed.packages() [1] FALSE FALSE TRUE > candidate_pak[!candidate_pak %in% installed.packages()] ## 过滤已经安装的包 [1] "qqman" "data.table" > candidate_pak <- candidate_pak[!candidate_pak %in% installed.packages()] ## 重新生成候选包向量 > candidate_pak [1] "qqman" "data.table" > install.packages(candidate_pak) ## 批量安装
参考:
001:https://mp.weixin.qq.com/s?__biz=MzI0MTIzNjYwNQ==&mid=2247487190&idx=1&sn=6dcfeefd5ea4aa197736826040e2db1b&chksm=e90fe1c4de7868d290ca14cca10670654b23f8b2bb32bd73c987fe3f233a7e1ae6e0ee96f92b&mpshare=1&scene=23&srcid=05084tQwhoY5uwhsPLpCaRKZ&sharer_sharetime=1651940014448&sharer_shareid=50b75c6a886e09824b582fb782a7678b#rd
002:https://blog.csdn.net/zyj15393961975/article/details/118207841