R语言中批量加载包
方法1:
> (.packages()) ## 查看已安装的包 [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods" [7] "base" > candidate_pak <- c("qqman", "data.table", "detectRUNS") > for (i in candidate_pak) { ## 利用for循环批量加载 + library(i, character.only = T) + } > (.packages()) [1] "detectRUNS" "data.table" "qqman" "stats" "graphics" [6] "grDevices" "utils" "datasets" "methods" "base"
方法2:
> (.packages()) ## 查看已经安装的包 [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods" [7] "base" > candidate_pak <- c("qqman", "data.table", "detectRUNS") ## 候选包 > lapply(candidate_pak, function(x){library(x, character.only = T)}) ## 利用lapply函数批量加载 > (.packages()) ## 查看已经安装的包 [1] "detectRUNS" "data.table" "qqman" "stats" "graphics" [6] "grDevices" "utils" "datasets" "methods" "base"
参考:https://blog.csdn.net/zyj15393961975/article/details/118207841