在ubuntu中运行./rarepng.R后,出现以下报错
Error in loadNamespace(x) : there is no package called ‘prettyunits’
Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted
检查后发现,是因为r包未安装导致,在ubuntu中安装r包r脚本会面临镜像源选择的问题,如果以下:
--- Please select a CRAN mirror for use in this session ---
Secure CRAN mirrors
1: 0-Cloud [https] 2: Australia (Canberra) [https]
3: Australia (Melbourne 1) [https] 4: Australia (Melbourne 2) [https]
5: Austria [https] 6: Belgium (Brussels) [https]
7: Brazil (PR) [https] 8: Brazil (RJ) [https]
9: Brazil (SP 1) [https] 10: Brazil (SP 2) [https]
11: Bulgaria [https] 12: Canada (MB) [https]
13: Canada (ON 1) [https] 14: Canada (ON 2) [https]
15: Chile (Santiago) [https] 16: China (Beijing 2) [https]
17: China (Beijing 3) [https] 18: China (Hefei) [https]
19: China (Hong Kong) [https] 20: China (Guangzhou) [https]
21: China (Jinan) [https] 22: China (Lanzhou) [https]
23: China (Nanjing) [https] 24: China (Shanghai 2) [https]
25: China (Shenzhen) [https] 26: Colombia (Cali) [https]
27: Costa Rica [https] 28: Cyprus [https]
29: Czech Republic [https] 30: Denmark [https]
31: East Asia [https] 32: Ecuador (Cuenca) [https]
33: France (Lyon 1) [https] 34: France (Lyon 2) [https]
35: France (Marseille) [https] 36: France (Paris 1) [https]
37: Germany (Erlangen) [https] 38: Germany (Göttingen) [https]
39: Germany (Leipzig) [https] 40: Germany (Münster) [https]
41: Greece [https] 42: Iceland [https]
43: India (Bengaluru) [https] 44: India (Bhubaneswar) [https]
45: Indonesia (Banda Aceh) [https] 46: Iran (Mashhad) [https]
47: Italy (Milano) [https] 48: Italy (Padua) [https]
49: Japan (Yonezawa) [https] 50: Korea (Gyeongsan-si) [https]
51: Mexico (Mexico City) [https] 52: Mexico (Texcoco) [https]
53: Morocco [https] 54: Netherlands (Dronten) [https]
55: New Zealand [https] 56: Norway [https]
57: South Africa (Johannesburg) [https] 58: Spain (A Coruña) [https]
59: Spain (Madrid) [https] 60: Sweden (Umeå) [https]
61: Switzerland (Zurich 1) [https] 62: Taiwan (Taipei) [https]
63: Turkey (Denizli) [https] 64: Turkey (Istanbul) [https]
65: UK (Bristol) [https] 66: UK (London 1) [https]
67: USA (IA) [https] 68: USA (MI) [https]
69: USA (MO) [https] 70: USA (OH) [https]
71: USA (OR) [https] 72: USA (PA 1) [https]
73: USA (TN) [https] 74: United Arab Emirates [https]
75: Uruguay [https] 76: (other mirrors)
我的r脚本中使用的是以下代码安装并加载r包,
load_or_install_packages <- function(package_names) {
for (pkg in package_names) {
if (!requireNamespace(pkg, quietly = TRUE)) {
install.packages(pkg, dependencies = TRUE)
library(pkg, character.only = TRUE)
} else {
library(pkg, character.only = TRUE)
}
}
}
Packages <- c("microeco", "magrittr", "vegan", "tidyr")
load_or_install_packages(Packages)
请问如何解决脚本运行中选择镜像源的自动化问题