Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a CRAN mirror in R

People also ask

Which CRAN mirror should I use for R?

If you are downloading R from CRAN, the following CRAN mirrors support HTTPS and we recommend using one of them: CRAN master (Austria): https://cran.r-project.org/ RStudio (USA): https://cran.rstudio.com/ Revolution Analytics (USA): https://cran.revolutionanalytics.com/

What is CRAN mirror?

CRAN is a network of ftp and web servers around the world that store identical, up-to-date, versions of code and documentation for R. Please use the CRAN mirror nearest to you to minimize network load.

How do you get CRAN in R?

Installing the CRAN packages with the menu In RStudio go to Tools → Install Packages and in the Install from option select Repository (CRAN) and then specify the packages you want. In classic R IDE go to Packages → Install package(s) , select a mirror and install the package.


You should either get a window with a list of repositories or a text menu with some options. But if that is not appearing, you can always specify the mirror from where to download the packages yourself by using repos parameter. By doing that, R will not ask you anymore about the repository. Example:

install.packages('RMySQL', repos='http://cran.us.r-project.org')

Here you have a list of mirrors for R.


Here is what I do, which is basically straight from the example(Startup) page:

## Default repo
local({r <- getOption("repos")
       r["CRAN"] <- "http://cran.r-project.org" 
       options(repos=r)
})

which is in ~/.Rprofile.

Edit: As it is now 2018, we can add that for the last few years the URL "https://cloud.r-project.org" has been preferable as it reflects a) https access and b) an "always-near-you" CDN.


I'm a fan of:

chooseCRANmirror()

Which will print the list of mirrors in the output (no worrying a popup window since you are running it from the terminal) and then you enter the number you want.


I use the ~/.Rprofile solution suggested by Dirk, but I just wanted to point out that

chooseCRANmirror(graphics=FALSE)

seems to be the sensible thing to do instead of

chooseCRANmirror(81)

, which may work, but which involves the magic number 81 (or maybe this is subtle way to promote tourism to 81 = UK (Bristol) :-) )


Repository selection screen cannot be shown on your system (OS X), since OS X no longer includes X11. R tries to show you the prompt through X11. Install X11 from http://xquartz.macosforge.org/landing/. Then run the install command. The repo selection prompt will be shown.


I used

chooseCRANmirror(81)

it gives you a prompt to select the country. Then you can do a selection by typing the country mirror code specified there.