Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell the R interpreter how to use the proxy server?

Tags:

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?

like image 710
Firefeather Avatar asked Jan 28 '11 20:01

Firefeather


People also ask

How do you check proxy server is working or not?

Click the “Connections” tab in the Internet Options window. Click the “LAN Settings” button. If there is a check mark in the box next to the “Us a proxy server for your LAN” option, then your PC accesses the Web through a proxy server. If there is no check mark in the box, your computer does not use a proxy server.

What is proxy R?

proxy: Distance and Similarity MeasuresProvides an extensible framework for the efficient calculation of auto- and cross-proximities, along with implementations of the most popular ones. Version: 0.4-27. Depends: R (≥ 3.4.0)


2 Answers

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)
like image 30
Jonas Tundo Avatar answered Oct 25 '22 12:10

Jonas Tundo


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:[email protected]:8080/"

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

like image 66
skullkey Avatar answered Oct 25 '22 12:10

skullkey