
Stephen F. answered 10/18/19
Experienced Tutor in R, Statistics, Programming, and Social Sciences
The easiest way is to add it as an option in your .Rprofile file. If you're on a Mac or Linux computer, you can put that file in your home directory, ~/.Rprofile. On Windows, you can put it in C:\Users\<YourUserName>\.Rprofile. The .Rprofile file itself is just R code that will get run every time you start up R. It often contains a lot of configuration settings, so it's the perfect place to set a permanent CRAN mirror. The contents of the file could look like this:
You first get the value of the "repos" option -- it likely isn't set, so it will just be an empty vector, but it's wise to be safe and make sure you don't overwrite existing settings. You next create an element in the vector, giving it the name "CRAN" and the value of the URL string for the mirror that you want. Finally, you write that setting back up into the options, so that it will take effect in your R session.
There are a lot of really interesting things you can do with R startup. If you're interested, you can read more about it in Efficient R Programming, a free O'Reilly ebook by Colin Gillespie and Robin Lovelace: https://csgillespie.github.io/efficientR/3-3-r-startup.html#r-startup