Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default CRAN mirror permanent in R

Tags:

r

r-faq

cran

How can I set a specific CRAN mirror permanently in R?

I want to set it permanently in my laptop so that when I do install.packages(), it won't ask me again which mirror to choose.

like image 506
719016 Avatar asked Oct 14 '22 18:10

719016


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.


1 Answers

You can set repos in your .Rprofile to restore your choice every time you start R

Edit: to be more precise:

Add

options(repos=structure(c(CRAN="YOUR FAVORITE MIRROR")))

to your .Rprofile


Alternatively, you can set the mirror site-wide in your Rprofile.site. The location of the file is given by ?Startup:

The path of this file is taken from the value of the R_PROFILE environment variable (after tilde expansion). If this variable is unset, the default is R_HOME/etc/Rprofile.site, which is used if it exists (which it does not in a 'factory-fresh' installation).

So do Sys.getenv("R_PROFILE") for the first option, or Sys.getenv("R_HOME") or R.home() for the second option. On macOS, the location of the second is /Library/Frameworks/R.framework/Resources/etc/.

The file may not exist, or you may see the following lines commented out :

# set a CRAN mirror
# local({r <- getOption("repos")
#       r["CRAN"] <- "http://my.local.cran"
#       options(repos=r)})

So remove the comment marks and change "http://my.local.cran" to the correct website, e.g.:

local({r <- getOption("repos")
       r["CRAN"] <- "http://cran.r-project.org"
       options(repos=r)})
like image 138
rinni Avatar answered Oct 17 '22 06:10

rinni