方案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")