21

I'm trying to get R (running on Windows) to download some packages from the Internet, but the download fails because I can't get it to correctly use the necessary proxy server. The output text when I try the Windows menu option Packages > Install package(s)... and select a CRAN mirror is:

> utils:::menuInstallPkgs()
--- Please select a CRAN mirror for use in this session ---
Warning: unable to access index for repository http://cran.opensourceresources.org/bin/windows/contrib/2.12
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.12
Error in install.packages(NULL, .libPaths()[1L], dependencies = NA, type = type) :
    no packages were specified
In addition: Warning message:
In open.connection(con, "r") :
    cannot open: HTTP status was '407 Proxy Authentication Required'

I know the address and port of the proxy, and I also know the address of the automatic configuration script. I don't know what the authentication is called, but when using the proxy (in a browser and some other applications), I enter a username and password in a dialog window that pops up.

To set the proxy, I tried each of the following:

  • Sys.setenv(http_proxy="http://proxy.example.com:8080")
  • Sys.setenv("http_proxy"="http://proxy.example.com:8080")
  • Sys.setenv(HTTP_PROXY="http://proxy.example.com:8080")
  • Sys.setenv("HTTP_PROXY"="http://proxy.example.com:8080")

For authentication, I similarly tried setting the http_proxy_user environment variable to:

  • ask
  • user:passwd
  • Leaving it untouched

Am I using the right commands in the right way?

Firefeather
  • 336
  • 1
  • 2
  • 12
  • 1
    Looks good. Did you also try starting R (on Windows, I presume?) with the --internet2 option? – Dirk Eddelbuettel Jan 28 '11 at 20:15
  • @Dirk E.: Yes; I checked and found that the Start Menu shortcut I run R from is set to use the `--internet2` option. (And yes, it's on Windows; I've edited the question now to make that clear.) – Firefeather Jan 28 '11 at 20:21
  • 1
    Ok, good, you could also try setting the key=value pairs of the env. variables in a file `Renviron` or even your installation-wide `Renviron.site` --- see `help(Startup)`. – Dirk Eddelbuettel Jan 28 '11 at 20:31
  • @Dirk E.: Same error when I tried putting it in my `Renviron.site`; `HTTP_PROXY` and `HTTP_PROXY_USER` are getting populated by the `Renviron.site` file. – Firefeather Jan 28 '11 at 22:22

3 Answers3

20

You have two options:

  1. Use --internet2 or setInternet2(TRUE) and set the proxy details in the control panel, in Internet Options
  2. Do not use either --internet2 or setInternet2(FALSE), but specify the environment variables

EDIT: One trick is, you cannot change your mind between 1 and 2, after you have tried it in a session, i.e. if you run the command setInternet2(TRUE) and try to use it e.g. install.packages('reshape2'), should this fail, you cannot then call setInternet2(FALSE). You have to restart the R session.

As of R version 3.2.0, the setInternet2 function can set internet connection settings and change them within the same R session. No need to restart.


When using option 2, one way (which is nice and compact) to specify the username and password is http_proxy="http://user:password@proxy.example.com:8080/"

In the past, I have had most luck with option 2

BenBarnes
  • 18,616
  • 6
  • 55
  • 72
skullkey
  • 791
  • 5
  • 6
4

If you want internet2 to be used everytime you use R you could add the following line to the Rprofile.site file which is located in R.x.x\etc\Rprofile.site

utils::setInternet2(TRUE)
Jonas Tundo
  • 5,877
  • 2
  • 34
  • 44
-3

install.packages("RCurl")

that will solve your problem.

G5W
  • 34,378
  • 10
  • 39
  • 71