【发布时间】:2014-05-14 18:43:45
【问题描述】:
更新
我在下面发布了一个有效的修复程序。它并没有完全解决问题,但它是一种解决方法。我仍然想让它工作,所以如果有人添加更好的解决方案,我会选择它!
问题
我正在尝试在 R 中设置环境变量以通过代理进行连接,但我所做的一切似乎都不起作用。 (编辑:我已经完成了我在其他类似帖子中发现的所有建议,通常是通过设置http_proxy 或以某种方式变体)
这是我的sessionInfo()
> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_3.1.0
我试过了:
- 在 .Renviron 和 .Rprofile 中设置“http_proxy”(包括所有大写字母和 https 变体)
- 在终端中设置代理变量。
- 通过
Sys.setenv(http_proxy="SERVER:PORT")设置代理变量 - 以上所有内容都适用于 RStudio 和命令行 R
然而,变量没有设置:
编辑:Martin Morgan 指出我需要在 getenv 通话中引用。变量已设置。
> Sys.getenv(http_proxy)
[1] ""
> Sys.setenv(http_proxy="SERVER:PORT")
> Sys.getenv(http_proxy)
[1] ""
不过,它似乎能够连接到代理,但无论我做什么,我都会得到以下一些变化:
> options(internet.info=0)
> source("http://bioconductor.org/biocLite.R")
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
In addition: Warning messages:
1: In file(filename, "r", encoding = encoding) :
connected to 'SERVER' on port PORT.
2: In file(filename, "r", encoding = encoding) :
-> (Proxy) GET http://bioconductor.org/biocLite.R HTTP/1.0
Host: bioconductor.org
Pragma: no-cache
User-Agent: R (3.0.3 x86_64-apple-darwin13.1.0 x86_64 darwin13.1.0)
3: In file(filename, "r", encoding = encoding) : <- HTTP/1.1 404 Not Found
4: In file(filename, "r", encoding = encoding) :
<- Content-Type: text/html
5: In file(filename, "r", encoding = encoding) :
<- Date: Wed, 14 May 2014 18:10:32 GMT
6: In file(filename, "r", encoding = encoding) : <- Connection: close
7: In file(filename, "r", encoding = encoding) : <- Server: mwg-ui
8: In file(filename, "r", encoding = encoding) :
Code 404, content-type 'text/html'
9: In file(filename, "r", encoding = encoding) :
cannot open: HTTP status was '404 Not Found'
您会注意到,在上面列出的情况下,我收到了404 错误;但是,我可以(并且确实)在浏览器中访问该文件。我也试过运行它:
> source("~/Downloads/biocLite.R")
Warning: unable to access index for repository http://www.bioconductor.org/packages/2.14/bioc/src/contrib
'biocLite.R' failed to install 'BiocInstaller', use
'install.packages("BiocInstaller",
repos="http://www.bioconductor.org/packages/2.14/bioc")'
Warning message:
package ‘BiocInstaller’ is not available (for R version 3.1.0)
> install.packages("BiocInstaller",
+ repos="http://www.bioconductor.org/packages/2.14/bioc")
Warning: unable to access index for repository http://www.bioconductor.org/packages/2.14/bioc/src/contrib
Warning message:
package ‘BiocInstaller’ is not available (for R version 3.1.0)
更新:尝试从命令行通过wget 和curl 下载http://bioconductor.org/biocLite.R。效果很好。
更新:根据不同来源的建议,我尝试了几件事。
-
在
.Renviron文件中的值周围加上单引号,即 `http_proxy='SERVER:PORT'。 这改变了一些东西,但仍然没有成功。另外,我发现 url 引号需要是双引号。来源('http://bioconductor.org/biocLite.R') 文件中的错误(文件名,“r”,编码 = 编码): 无法打开连接 来源("http://bioconductor.org/biocLite.R") 警告:无法访问存储库http://www.bioconductor.org/packages/2.14/bioc/src/contrib 的索引 “biocLite.R”未能安装“BiocInstaller”,请使用 'install.packages("BiocInstaller", repos="http://www.bioconductor.org/packages/2.14/bioc")' 警告信息: 包‘BiocInstaller’不可用(适用于 R 版本 3.1.0)
-
使用空的 .Renviron 文件和新终端,运行
R --vanilla并安装。这是为了确保需要设置代理。确实如此。来源('http://bioconductor.org/biocLite.R') 文件中的错误(文件名,“r”,编码 = 编码): 无法打开连接 另外:警告信息: 在文件(文件名,“r”,编码=编码): 无法连接到端口 PORT 上的“bioconductor.org”。
-
在
Sys.getenv调用周围使用引号:[有效,但不能解决问题]Sys.getenv("http_proxy") [1]“http://服务器:端口/”
【问题讨论】:
-
标题是什么?你有 v3.1.0 而不是 3.03
-
啊...谢谢。我从 3.03 开始,然后在尝试弄清楚时进行了更新。无论哪种方式,结果都相同。
-
引用
Sys.getenv("http_proxy")的参数,虽然我看不出这对你的问题有什么帮助。 -
它确实修复了
getenv调用。谢谢!
标签: r macos proxy bioconductor