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:
- setting 'http_proxy' (including all caps and https variations) in .Renviron and .Rprofile
- setting the proxy variables in the terminal.
- setting the proxy variables via
Sys.setenv(http_proxy="SERVER:PORT")
- 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.
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)
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.
Use quotes around the
Sys.getenv
call: [worked, but doesn't fix the problem]Sys.getenv("http_proxy") [1] "http:// SERVER : PORT /"
Sys.getenv("http_proxy")
, although I don't see how that helps with your problem. – Martin Morgangetenv
call. Thank you! – muppetjones