Linux安装R包时窗口抓取失败

Perl, R

Posted by dulunar on May 18, 2021 | 访问量:

前言

在Linux上的R中install.packages时,经常会出现窗口抓取失败的情况,如下:

> install.packages("ggplot2")
Installing package into /home/luna/Desktop/Software/RSoft/lib64/R/library
(as lib is unspecified)
--- Please select a CRAN mirror for use in this session ---
Error in structure(.External(.C_dotTclObjv, objv), class = "tclObj") :
  [tcl] grab failed: window not viewable.
> 

意思是,窗口抓取失败,这是因为调用 TCLTK 窗口时,窗口因为某些原因(如使用ssh工具连接linux)无法弹出,所以出现错误无法选择mirror。

解决方案

在install.packages之前,先输入chooseCRANmirror(graphics=FALSE),选择合适的mirror后再安装:

> chooseCRANmirror(graphics=FALSE)
Secure CRAN mirrors

 1: 0-Cloud [https]
 2: Australia (Canberra) [https]
 3: Australia (Melbourne 1) [https]
 4: Australia (Melbourne 2) [https]
 5: Australia (Perth) [https]
 6: Austria [https]
 7: Brazil (BA) [https]
 8: Brazil (PR) [https]
 9: Brazil (RJ) [https]
10: Brazil (SP 1) [https]
11: Brazil (SP 2) [https]
12: Bulgaria [https]
13: Canada (MB) [https]
14: Canada (ON 2) [https]
15: Chile (Santiago) [https]
16: China (Beijing 2) [https]
17: China (Hefei) [https]
18: China (Hong Kong) [https]
19: China (Guangzhou) [https]
20: China (Lanzhou) [https]
21: China (Nanjing) [https]
22: China (Shanghai 1) [https]
23: China (Shanghai 2) [https]
24: Costa Rica [https]
25: Denmark [https]
26: East Asia [https]
27: Ecuador (Cuenca) [https]
28: Ecuador (Quito) [https]
29: Estonia [https]
30: France (Lyon 1) [https]
31: France (Lyon 2) [https]
32: France (Marseille) [https]
33: France (Montpellier) [https]
34: Germany (Erlangen) [https]
35: Germany (Leipzig) [https]
36: Germany (Göttingen) [https]
37: Germany (Münster) [https]
38: Germany (Regensburg) [https]
39: Greece [https]
40: Hungary [https]
41: Iceland [https]
42: India [https]
43: Indonesia (Jakarta) [https]
44: Iran [https]
45: Italy (Milano) [https]
46: Italy (Padua) [https]
47: Japan (Tokyo) [https]
48: Korea (Gyeongsan-si) [https]
49: Korea (Seoul 1) [https]
50: Korea (Ulsan) [https]
51: Malaysia [https]
52: Mexico (Mexico City) [https]
53: Morocco [https]
54: Netherlands [https]
55: New Zealand [https]
56: Norway [https]
57: Philippines [https]
58: Russia (Moscow) [https]
59: South Africa (Johannesburg) [https]
60: Spain (A Coruña) [https]
61: Spain (Madrid) [https]
62: Sweden (Borås) [https]
63: Sweden (Umeå) [https]
64: Switzerland [https]
65: Taiwan (Taipei) [https]
66: Turkey (Denizli) [https]
67: Turkey (Istanbul) [https]
68: Turkey (Mersin) [https]
69: UK (Bristol) [https]
70: UK (London 1) [https]
71: USA (IA) [https]
72: USA (KS) [https]
73: USA (MI) [https]
74: USA (OH) [https]
75: USA (OR) [https]
76: USA (TN) [https]
77: USA (TX 1) [https]
78: Uruguay [https]
79: (other mirrors)

Selection: 21
> install.packages("ggplot2")
Installing package into /home/luna/Desktop/Software/RSoft/lib64/R/library
(as lib is unspecified)
trying URL 'https://mirrors.nju.edu.cn/CRAN/src/contrib/ggplot2_3.3.3.tar.gz'
Content type 'application/octet-stream' length 3058840 bytes (2.9 MB)
==================================================
downloaded 2.9 MB

* installing *source* package ggplot2 ...
** package ggplot2 successfully unpacked and MD5 sums checked
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (ggplot2)

The downloaded source packages are in
        /tmp/RtmpXRoaiP/downloaded_packages