Update
更新
I posted a working fix below. It doesn't completely solve the problem, but it is a work around. I would still like to get it working, so if anyone adds a better solution, I'll select it!
我在下面发布了一个工作补丁。这并不能完全解决问题,但这是一项工作。我仍然想让它工作,所以如果有人添加更好的解决方案,我将选择它!
Problem
I am trying to set environment variables in R in order to connect through a proxy, but nothing I do seems to work. (edit: I have done everything I have found suggested in other similar posts, which is usually via setting http_proxy
or variants in some manner)
我试图在R中设置环境变量,以便通过代理连接,但是我所做的一切似乎都没有效果。(编辑:我已经完成了我在其他类似帖子中所发现的所有建议,通常是通过设置http_proxy或一些变体)
Here is my sessionInfo()
这是我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
I have tried:
我有尝试:
- setting 'http_proxy' (including all caps and https variations) in .Renviron and .Rprofile
- 在. renvironment和.Rprofile中设置“http_proxy”(包括所有大写和https变体)。
- setting the proxy variables in the terminal.
- 在终端中设置代理变量。
- setting the proxy variables via
Sys.setenv(http_proxy="SERVER:PORT")
- 通过Sys.setenv设置代理变量(http_proxy="SERVER:PORT")
- all of the above for both RStudio and command line R
- 以上所有内容均适用于RStudio和命令行R。
Yet, the variable is not set: Edit: Martin Morgan pointed out that I needed quotations in the getenv
call. The variable is set.
然而,该变量没有设置:编辑:Martin Morgan指出,我需要getenv调用中的引用。变量集。
> Sys.getenv(http_proxy)
[1] ""
> Sys.setenv(http_proxy="SERVER:PORT")
> Sys.getenv(http_proxy)
[1] ""
Still, it seems to be able to connect to the proxy, but no matter what I do, I get some variation of the following:
尽管如此,它似乎能够连接到代理,但是无论我做什么,我都会得到以下的一些变化:
> 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'
You will notice that in the case listed above, I get a 404
error; however, I can (and did) access the file in browser. I tried running it as well:
你会注意到,在上面列出的例子中,我有一个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)
Update: Tried downloading http://bioconductor.org/biocLite.R
via wget
and curl
from the command line. Works just fine.
更新:尝试从命令行通过wget和curl下载http://biodirector.org/bioclite.r。工作得很好。
Update: I tried a couple of things after suggestions from different sources.
更新:我从不同来源的建议中尝试了几件事情。
-
Put single quotes around the values in the
.Renviron
file, i.e., `http_proxy='SERVER:PORT'. This changed something, but still no success. Also, I found out that the url quotes need to be double.将单引号括在. renvironment文件中,即。‘http_proxy = '服务器:港口”。这改变了一些东西,但仍然没有成功。另外,我发现url引号需要加倍。
source('http://bioconductor.org/biocLite.R') Error in file(filename, "r", encoding = encoding) : cannot open the connection source("http://bioconductor.org/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)
文件中的错误(文件名,“r”,编码=编码):无法打开连接源(“http://bioconductor.org/biocLite.R”)警告:无法访问存储库http://www.bioconductor.org/packages/2.14/ bioc/src/b的biocLite。R'未能安装'BiocInstaller',使用'install '。软件包("BiocInstaller", repos="http://www.bioconductor.org/packages/2.14/bioc")的警告信息:包的BiocInstaller '不可用(R版本3.1.0)
-
With an empty .Renviron file and a fresh terminal, run
R --vanilla
and install. This was intended to ensure that the proxy needed to be set. And it does.带一个空的. renvironment文件和一个新的终端,运行R——vanilla并安装。这是为了确保需要设置代理。
source('http://bioconductor.org/biocLite.R') Error in file(filename, "r", encoding = encoding) : cannot open the connection In addition: Warning message: In file(filename, "r", encoding = encoding) : unable to connect to 'bioconductor.org' on port PORT.
在文件(文件名,“r”,编码=编码)中出现的错误:不能打开连接:在文件中警告信息:文件(文件名,“r”,编码=编码):无法连接到端口端口上的“bioconductor.org”。
-
Use quotes around the
Sys.getenv
call: [worked, but doesn't fix the problem]在系统中使用引号。getenv电话:[工作,但没有解决问题]
Sys.getenv("http_proxy") [1] "http:// SERVER : PORT /"
getenv("http_proxy") [1] "http://服务器:端口/"
1 个解决方案
#1
1
Thanks to the comment from @zhanxw, I took another look at what was going on, and I realized that although the proxy server was being accessed, R was using the wrong port.
由于@zhanxw的评论,我再次查看了正在发生的事情,我意识到虽然代理服务器正在被访问,但是R使用了错误的端口。
Here's why: I had an extra forwardslash at the end of my http_proxy
, which (I'm assuming) caused R to parse the environment variable incorrectly. http_proxy="http://[SERVER]:[PORT]/" Once I removed the trailing forward slash, it works fine.
原因如下:我在http_proxy的末尾有一个额外的转发,它(我假设)导致R对环境变量的解析不正确。http://[服务器]:[端口]/“一旦我删除了后面的斜杠,它就可以正常工作了。
Below is the original "solution" I posted.
下面是我发布的原始“解决方案”。
A workaround, but not a complete solution:
一个变通方案,但不是一个完整的解决方案:
options(download.file.method="wget")
This still does not fix the original problem:
这仍然不能解决原来的问题:
source("http://bioconductor.org/biocLite.R") Error in file(filename, "r", encoding = encoding) : cannot open the connection
文件中的错误(文件名,“r”,编码=编码):无法打开连接。
But it does allow for an alternative method to work:
但它确实允许另一种工作方式:
> install.packages("BiocInstaller", repos="http://bioconductor.org/packages/2.14/bioc")--2014-05-14 16:08:18-- http://bioconductor.org/packages/2.14/bioc/src/contrib/BiocInstaller_1.14.2.tar.gz
Resolving SERVER... IP, IP, IP, ...
Connecting to SERVER|IP|:PORT... connected.
Proxy request sent, awaiting response... 200 OK
Length: 14053 (14K) [application/x-gzip]
Saving to: '/var/folders/p1/5gstd7bn1hb1t8pd6b7bp5n00000gp/T//RtmpFm0GR3/downloaded_packages/BiocInstaller_1.14.2.tar.gz'
100%[=============================================>] 14,053 --.-K/s in 0s
#1
1
Thanks to the comment from @zhanxw, I took another look at what was going on, and I realized that although the proxy server was being accessed, R was using the wrong port.
由于@zhanxw的评论,我再次查看了正在发生的事情,我意识到虽然代理服务器正在被访问,但是R使用了错误的端口。
Here's why: I had an extra forwardslash at the end of my http_proxy
, which (I'm assuming) caused R to parse the environment variable incorrectly. http_proxy="http://[SERVER]:[PORT]/" Once I removed the trailing forward slash, it works fine.
原因如下:我在http_proxy的末尾有一个额外的转发,它(我假设)导致R对环境变量的解析不正确。http://[服务器]:[端口]/“一旦我删除了后面的斜杠,它就可以正常工作了。
Below is the original "solution" I posted.
下面是我发布的原始“解决方案”。
A workaround, but not a complete solution:
一个变通方案,但不是一个完整的解决方案:
options(download.file.method="wget")
This still does not fix the original problem:
这仍然不能解决原来的问题:
source("http://bioconductor.org/biocLite.R") Error in file(filename, "r", encoding = encoding) : cannot open the connection
文件中的错误(文件名,“r”,编码=编码):无法打开连接。
But it does allow for an alternative method to work:
但它确实允许另一种工作方式:
> install.packages("BiocInstaller", repos="http://bioconductor.org/packages/2.14/bioc")--2014-05-14 16:08:18-- http://bioconductor.org/packages/2.14/bioc/src/contrib/BiocInstaller_1.14.2.tar.gz
Resolving SERVER... IP, IP, IP, ...
Connecting to SERVER|IP|:PORT... connected.
Proxy request sent, awaiting response... 200 OK
Length: 14053 (14K) [application/x-gzip]
Saving to: '/var/folders/p1/5gstd7bn1hb1t8pd6b7bp5n00000gp/T//RtmpFm0GR3/downloaded_packages/BiocInstaller_1.14.2.tar.gz'
100%[=============================================>] 14,053 --.-K/s in 0s