R语言中批量加载R包
001、
packages <- c("data.table", "ggplot2", "qqman", "detectRUNS") ## 确保包已经安装 sapply(packages, require) sapply(packages, require, character.only = TRUE) ## 批量加载
002、
packages <- c("data.table", "ggplot2", "qqman", "detectRUNS") for (i in 1:length(packages)) { if (packages[i] %in% installed.packages()[,"Package"]) { next } else { install.packages(packages[i], dependencies = TRUE) } } sapply(packages, require, character.only = TRUE)