1. 程式人生 > 其它 >R語言中批量載入包

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