Pregunta

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)

Here is my 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:

  1. setting 'http_proxy' (including all caps and https variations) in .Renviron and .Rprofile
  2. setting the proxy variables in the terminal.
  3. setting the proxy variables via Sys.setenv(http_proxy="SERVER:PORT")
  4. all of the above for both RStudio and command line R

Yet, the variable is not set: Edit: Martin Morgan pointed out that I needed quotations in the getenv call. The variable is set.

> 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:

> 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.

Update: I tried a couple of things after suggestions from different sources.

  1. 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.

    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)

  2. 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.

    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.

  3. Use quotes around the Sys.getenv call: [worked, but doesn't fix the problem]

    Sys.getenv("http_proxy") [1] "http:// SERVER : PORT /"

¿Fue útil?

Solución

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.

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.

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

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    
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top