简体   繁体   English

无法永久更改 R (OS X) 中的 CRAN 存储库

[英]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.我正在努力弄清楚为什么我无法在我的 OS X 10.11.3 系统上永久更改 R 中使用的 CRAN 存储库。 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:我已经按照 web 中的说明进行操作,例如这个 SO questionthis SO question以及这个网页,并将其放入 my.Rprofile 文件中:

# 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.这个片段几乎直接来自 R 自己的example("Startup")的东西,而且它确实看起来应该可以工作。 I have it as the first thing in my .Rprofile , and the rest of my .Rprofile is trivial and does not touch this option.我把它作为我的.Rprofile的第一件事,而我的 .Rprofile 的.Rprofile是微不足道的,不会触及这个选项。 If I quit an relaunch R.app, I see this output from my print statement, at the appropriate place in the startup:如果我退出重新启动 R.app,我会从我的print语句中看到这个 output,在启动的适当位置:

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

So that looks great, right?所以看起来很棒,对吧? Unfortunately, if I then type getOption("repos") I get this:不幸的是,如果我然后输入getOption("repos")我得到这个:

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

Unfortunately, the parentingamerica.com mirror appears to be dead, at least today.不幸的是, parentingamerica.com镜像似乎已经死了,至少今天是这样。 Somebody is setting the option after my .Rprofile , and I can't figure out who.有人在我的.Rprofile之后设置选项,我不知道是谁。 I have no ~/.RData file;我没有~/.RData文件; 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.我没有.Rprofile.site文件,R 安装中的Renviron文件是默认文件,没有提及“parentingamerica.com”,也没有设置"repos"选项。 Indeed, I have done a find/grep on my entire R.framework directory for any file containing "parentingamerica" and have come up empty-handed.事实上,我已经在我的整个R.framework目录上对任何包含“parentingamerica”的文件进行了查找/grep,并且空手而归。 The only things in my R_HOME/etc/ directory are Makecof, Renviron, javaconf, ldpaths, and repositories.我的R_HOME/etc/目录中只有 Makecof、Renviron、javaconf、ldpaths 和存储库。 I'm not sure what that repositories file is used for exactly, but it does not contain "parentingamerica".我不确定该存储库文件的确切用途,但它不包含“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??知道这个 %^$@* parentingamerica.com 选项是从哪里来的,我怎么能把它杀死?

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:然后我在文本上退格并关闭首选项对话框,退出 R,并编辑我的 .Rprofile 文件以包含以下行:

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

I then opened up an R.app session and see this result:然后我打开了一个 R.app 会话并看到了这个结果:

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

The Preferences/Startup panel shows the default CRAN mirror setting to remain blank.首选项/启动面板显示默认的 CRAN 镜像设置保持空白。 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.所以在我看来,首选项设置的行为确实允许您使用 .Rprofile 来选择默认存储库,如果这是您选择的策略。 (I also checked that this repo setting was honored by the Package Installer.) (我还检查了包安装程序是否支持此 repo 设置。)

And right at the end of writing this post, it occurred to me to check in R.app's various settings and preferences.在写这篇文章的最后,我突然想到要检查 R.app 的各种设置和首选项。 And there, in the Startup panel of R.app's preferences, is "Default CRAN mirror", set to http://cran.parentingamerica.com .在那里,在 R.app 首选项的启动面板中,是“默认 CRAN 镜像”,设置为http://cran.parentingamerica.com Aargh.啊。 Thanks, R.app!谢谢,R.app! There is no obvious way to turn that off and have it just use the one set in my .Rprofile ;没有明显的方法可以关闭它并让它只使用我的.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.如果 .Rprofile 未在 Mac OS X 上加载,另一件要检查的事情(如果 42 的解决方案不起作用)是检查主目录的路径。 Many of the help files on this problem mention关于这个问题的许多帮助文件都提到

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

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

But it should work if you point it to /Users/yourname/.Rprofile:但是如果您将其指向 /Users/yourname/.Rprofile,它应该可以工作:

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

I had similar code in my.Rprofile that wasn't being recognized for whatever reason.我在 my.Rprofile 中有类似的代码,无论出于何种原因都没有被识别。 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. ind = 0表示您只想要本地存储库。 Additional repositories can be included in the addURLs = option and are comma separated within the character vector.附加存储库可以包含在addURLs =选项中,并在字符向量中以逗号分隔。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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