Set the default CRAN mirror to R

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

I want to install it constantly on my laptop so that when I do install.packages() , it will not ask me which mirror to choose.

+87
r r-faq cran
Dec 12 '11 at 1:30 p.m.
source share
1 answer

You can install repositories in your .Rprofile to restore your selection 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 install a mirror for the entire site in your Rprofile.site . The file location is defined as ?Startup :

The path to this file is taken from the value of the environment variable R_PROFILE (after R_PROFILE tilde). If this variable is not set, the default is R_HOME/etc/Rprofile.site , which is used if it exists (which is not the case with a factory installation).

So 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 /Library/Frameworks/R.framework/Resources/etc/ is /Library/Frameworks/R.framework/Resources/etc/ .

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

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

Therefore, unmark the comments and change " http: //my.local.cran " to the correct website, for example:

 local({r <- getOption("repos") r["CRAN"] <- "http://cran.r-project.org" options(repos=r)}) 
+105
Dec 12 '11 at 13:40
source share



All Articles