Wednesday, June 10, 2026

CRAN Repository Selection

RStudio gives you some control over the installation of packages via the menu path Tools > Global Options... > Packages. On the rare occasions I went there, I got a warning message at the top of the panel: "CRAN repositories modified outside package preferences". I'm not sure if this means that changes made in the settings dialog will not have any effect at all, or whether their effect will be limited to that RStudio session. Either way, until today I paid it no mind.

For reasons best captured by the saying "idle hands are the devil's workshop", I decided this morning to try to fix the problem. A Google search convinced me that other people are encountering this but was a bit shy of specifics on how to fix it. I did learn that running getOption("repos") in the RStudio console (or in an R session outside RStudio) would tell me where R would look for packages for installation or update. On my system (Linux Mint), it was defaulting to https://cloud.r-project.org. So the next step was to figure out where that was being set.

After considerable poking around, I found that code at the bottom of /etc/R/Rprofile.site was setting the option. After editing the file (as root) and commenting out that code, I restarted RStudio and found that the error message was gone. RStudio now points to  https://cran.rstudio.com/ (which may or may not be a mirror of the first site).

So what happens now if I run R from a terminal (outside RStudio) and try to install/update packages? With the original option no longer set, R pops up a list of mirrors and has me pick one. It's an extra step I could live without, but since I normally install packages from RStudio and not a plain R session, I'm content to leave the change in place. I suspect, though, that the next time I upgrade R itself I will have to remember to edit the global Rprofile.site file again. 

No comments:

Post a Comment

Due to intermittent spamming, comments are being moderated. If this is your first time commenting on the blog, please read the Ground Rules for Comments. In particular, if you want to ask an operations research-related question not relevant to this post, consider asking it on Operations Research Stack Exchange.