简体   繁体   中英

Can't permanently change the CRAN repository in R (OS X)

I'm tearing my hair out trying to figure out why I am unable to permanently change the CRAN repository used in R on my OS X 10.11.3 system. I've followed the instructions that are all over the web, such as this SO question and this SO question and this webpage , and have put this into my.Rprofile file:

# Change the default repository
local({r <- getOption("repos")
       r["CRAN"] <- "https://cran.cnr.berkeley.edu/" 
       options(repos=r)
})
print(getOption("repos"))

This snippet is pretty much straight from R's own example("Startup") stuff, and it sure seems like it ought to work. I have it as the first thing in my .Rprofile , and the rest of my .Rprofile is trivial and does not touch this option. If I quit an relaunch R.app, I see this output from my print statement, at the appropriate place in the startup:

                            CRAN 
"https://cran.cnr.berkeley.edu/" 

So that looks great, right? Unfortunately, if I then type getOption("repos") I get this:

                              CRAN 
"http://cran.parentingamerica.com" 

Unfortunately, the parentingamerica.com mirror appears to be dead, at least today. Somebody is setting the option after my .Rprofile , and I can't figure out who. I have no ~/.RData file; no workspace is getting loaded on launch. I have no .Rprofile.site file, and the Renviron file in the R install is the default one, with no mention of "parentingamerica.com" and no setting of the "repos" option. Indeed, I have done a find/grep on my entire R.framework directory for any file containing "parentingamerica" and have come up empty-handed. The only things in my R_HOME/etc/ directory are Makecof, Renviron, javaconf, ldpaths, and repositories. I'm not sure what that repositories file is used for exactly, but it does not contain "parentingamerica".

I've been going around and around on this all morning. Any idea where this %^$@* parentingamerica.com option is coming from and how I can kill it dead??

I pasted an image of the state of my Startup panel into your answer. I then backspaced over the text and closed the Preferences dialog, exited R, and edited my .Rprofile file to include this line:

options(repos="https://cloud.r-project.org/")

I then opened up an R.app session and see this result:

> getOption('repos')
[1] "https://https://cloud.r-project.org/"

The Preferences/Startup panel shows the default CRAN mirror setting to remain blank. So it appears to me that the behavior of the Preferences settings does allow you to use .Rprofile to select your default repository if that is your chosen strategy. (I also checked that this repo setting was honored by the Package Installer.)

And right at the end of writing this post, it occurred to me to check in R.app's various settings and preferences. And there, in the Startup panel of R.app's preferences, is "Default CRAN mirror", set to http://cran.parentingamerica.com . Aargh. Thanks, R.app! There is no obvious way to turn that off and have it just use the one set in my .Rprofile ; but at least I can change it there and it works. Posting this to help others who go down the same path.

在此处输入图片说明

If the .Rprofile is not loading on Mac OS X another thing to check (if 42's solution isn't working) is to check the path to the home directory. Many of the help files on this problem mention

file.path(R.home(), ".Rprofile")

which points to /Library/Frameworks/R.framework/Resources/.Rprofile

But it should work if you point it to /Users/yourname/.Rprofile:

file.path(Sys.getenv("HOME"), ".Rprofile")

I had similar code in my.Rprofile that wasn't being recognized for whatever reason. Try this instead, which ended up working for me:

utils::setRepositories(ind = 0, addURLs = c(CRAN = "https://cran.cnr.berkeley.edu/"))

ind = 0 will indicate that you only want the local repository. Additional repositories can be included in the addURLs = option and are comma separated within the character vector.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM