1

I am running R in a Linux shell script and I need the code to run on its own. Currently I have to run install.packages("RJDBC") inside here and it keeps pausing the code to ask me about the CRAN mirror (In my case I need it to be 51).

In other words, I'm running the below code and I need it to avoid asking me what the CRAN mirror is and I need it to be selected automatically without stopping the code. (Everything after > is all I'm running before my code stops), the rest is output.

> #Libraries and Packages--------------
> install.packages("RJDBC") #Selection: 51 (Spain (Madrid))

[1] Installing package into ‘/usr/lib64/R/library’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Secure CRAN mirrors

 1: 0-Cloud [https]                   2: Algeria [https]
 3: Australia (Canberra) [https]      4: Australia (Melbourne 1) [https]
 5: Australia (Melbourne 2) [https]   6: Australia (Perth) [https]
 7: Austria [https]                   8: Belgium (Ghent) [https]
 9: Brazil (PR) [https]              10: Brazil (RJ) [https]
11: Brazil (SP 1) [https]            12: Brazil (SP 2) [https]
13: Bulgaria [https]                 14: Chile 1 [https]
15: Chile 2 [https]                  16: China (Guangzhou) [https]
17: China (Lanzhou) [https]          18: China (Shanghai 1) [https]
19: China (Shanghai 2) [https]       20: Colombia (Cali) [https]
21: Czech Republic [https]           22: Denmark [https]
23: East Asia [https]                24: Ecuador (Cuenca) [https]
25: Ecuador (Quito) [https]          26: Estonia [https]
27: France (Lyon 1) [https]          28: France (Lyon 2) [https]
29: France (Marseille) [https]       30: France (Montpellier) [https]
31: France (Paris 2) [https]         32: Germany (Erlangen) [https]
33: Germany (Göttingen) [https]      34: Germany (Münster) [https]
35: Greece [https]                   36: Iceland [https]
37: India [https]                    38: Indonesia (Jakarta) [https]
39: Ireland [https]                  40: Italy (Padua) [https]
41: Japan (Tokyo) [https]            42: Japan (Yonezawa) [https]
43: Korea (Seoul 1) [https]          44: Korea (Ulsan) [https]
45: Malaysia [https]                 46: Mexico (Mexico City) [https]
47: Norway [https]                   48: Philippines [https]
49: Serbia [https]                   50: Spain (A Coruña) [https]
51: Spain (Madrid) [https]           52: Sweden [https]
53: Switzerland [https]              54: Turkey (Denizli) [https]
55: Turkey (Mersin) [https]          56: UK (Bristol) [https]
57: UK (Cambridge) [https]           58: UK (London 1) [https]
59: USA (CA 1) [https]               60: USA (IA) [https]
61: USA (KS) [https]                 62: USA (MI 1) [https]
63: USA (NY) [https]                 64: USA (OR) [https]
65: USA (TN) [https]                 66: USA (TX 1) [https]
67: Vietnam [https]                  68: (other mirrors)


Selection:
  • You only need to install it once. Then you must change `install.pacakges("RJDBC")` to `library(RJDBC)`. – patL Jun 15 '18 at 07:30
  • 1
    Possible duplicate of [How to select a CRAN mirror in R](https://stackoverflow.com/questions/11488174/how-to-select-a-cran-mirror-in-r) – pieca Jun 15 '18 at 07:45
  • I strongly recommend using the 0-cloud: `repos = "https://cloud.r-project.org"`, but you can specify any mirror this way to `install.packages`. Also, `if (!require("RJDBC")) {install.packages("RJDBC", repos = "https://cloud.r-project.org"); library(RJDBC)}`. Finally, read `help("options")` (scroll down to `repos`). – Roland Jun 15 '18 at 08:00
  • Thanks! By using repos = "the link I needed" it did exactly what I needed. – Kevin Kaufman Jun 18 '18 at 15:37
  • It seems like a duplicate but the other question I could not find regarding the way I found my problem. Try adding the syntax of my question over there. – Kevin Kaufman Jun 18 '18 at 15:40

0 Answers0