719016 719016 - 1 month ago 14
R Question

Set default CRAN mirror permanent in R

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.

Answer

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 check your Rprofile.site (in the directory /your-R-installation/etc/ , eg R-2.14.0/etc). There you see 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.

Comments