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

4 Answers4

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
  • 19,114
  • 6
  • 56
  • 74
skullkey
  • 781
  • 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
  • 6,137
  • 2
  • 35
  • 45
  • "... as of R 3.3.0, is now defunct ... " as I've found in https://docs.tibco.com/pub/enterprise-runtime-for-R/6.0.0/doc/html/Language_Reference/utils/setInternet2.html – Tiziano Oct 17 '22 at 15:11
0

I've solved my trouble editing the file .Renviron as documented in Proxy setting for R.

EDITED

The solutions based on the setInternet2 statement do not work with the recent R versions because setInternet2 is declared defunct.

I'm using the 4.2.1 (on Win 11Pro) while I never had any problems in previous versions .

So to solve the problem need to modify some config files in order to fix the proxy issue not only for packages installation but, in general, also to acced to a remote resource (ie. boundary maps in my case).

The question "Proxy setting for R" collect a lot of solutions. I've found that this one has solved both my problems (packages installation and remote resources) explaining step-by-step how to edit the file .Renviron

Other solutions based on the customization of the file Renviron.site for me doesn't work

Tiziano
  • 271
  • 1
  • 5
  • 9
  • Please state clearly that you turned a comment into a question giving credit to the comments author. If I misunderstood and your solution is in fact only linked, please flag as duplicate instead of using an answer post to link to that other question. If this is not a duplicate please explain the difference and tailor the answer. – Yunnosch Oct 17 '22 at 16:52
  • I apologize but it was not my intention to take an action to earn credits but only to give an updated reference because the answers to this question cannot be used with updated versions of R. Since I don't know how to classify a question as DUPLICATE and I'm not a stackoverflow expert maybe it's better to delete my post? – Tiziano Oct 18 '22 at 16:25
  • I am trying to help you. If you don't know what "flag as duplicate" means I will explain in more detail. (And if I am wrong tell me, this might be different for you than for me....) Since reputation 15 you should have the privilege to flag posts. Please look that up here https://stackoverflow.com/help/privileges One of the flags you should be able to raise on a post is "duplicate". You can set that, and provide a link to the Q/A which you think provides the solution. Only if it really has a solution for the problem describe here. Please read and try and let me know. – Yunnosch Oct 18 '22 at 16:44
  • I did not get the details of " the answers to this question cannot be used with updated versions of R". But it could be the appreciated contribution (I lack the technical knowhow....). You might be able to create an answer which reference an existing answer and then explain something on top of it. If that is needed to be able to apply otherwise the answer you linked (and otherwise it does not help), then explaining and linking is fine. Not a duplicate. But that explanation is not yet in your answer. Add it. Maybe some other user than me can tell duplicate or not and will comment helpfully. – Yunnosch Oct 18 '22 at 16:47
  • I've found the flag DUPLICATE (Actually, it was not such a hidden option, I simply did not feel confident enough to give such an indication and did not look into how to do it. Thank you for your encouragement). – Tiziano Oct 19 '22 at 07:00
  • I will take advantage of your patience: How do I indicate the sixth answer (of the twelve available) given to question https://stackoverflow.com/questions/6467277/proxy-setting-for-r? And more: because this question is written 11 year and 8 months a go while my solution was posted 11 year and 3 months a go is correct tag as duplicated the older question? – Tiziano Oct 19 '22 at 07:01
  • In more detail about the answers to this question I've tried to apply the setInternet2 option but, I found, is not supported by the current R version. So I've written a short comment to the 3rd answer – Tiziano Oct 19 '22 at 07:02
  • To indicate one of many answers, use the "Share" link beneath it. But for duplicate proposal you anyway are asked for a question, which there is only one of on each page. Maybe I did not really get what you are asking for. – Yunnosch Oct 19 '22 at 07:07
  • Do not worry about which question or answer is older. Propose the better answered one as a duplicate by flagging the less helpfully answered question. – Yunnosch Oct 19 '22 at 07:08
  • If you propose a duplicate and want to highlighting a specific answer should not be necessary. The question needs to describe the same problem, then any answer should be as helpful as its votes indicate. But if you still want to point one out, maybe with a detail within that answer, you can use your commenting privilege, on the answer or on either of the two questions. – Yunnosch Oct 19 '22 at 07:53
  • The worst that can happen if you flag anything is that you get an explanation why the flag was not accepted and one count on "declined flags". Some people worry a lot to avoid that. But a few declined tickets are the path to learn. Just read the privilege explanation thoroughly. Also Meta posts can be searched if anything seems unclear. – Yunnosch Oct 19 '22 at 07:59
-3

install.packages("RCurl")

that will solve your problem.

G5W
  • 36,531
  • 10
  • 47
  • 80