DKK
DKK

Reputation: 1920

How to install R packages via proxy [user + password]

I need authentication to use internet, say these are my variables:

  1. Proxy : 1ncproxy1
  2. Port : 80
  3. Loggin : MyLoGiN
  4. Pass : MyPaSs

How can I install a package in R and its addon packages ? Such that the following would work:

install.packages("TSA", dependencies=TRUE)

Without our having internet connection failutes?

I tried this:

Sys.setenv("ftp_proxy" = "1ncproxy1","ftp_proxy_user"="MyLoGiN","ftp_proxy_password"="MyPaSs")#Port = 80

ButI get :

Warning: unable to access index for repository http://cran.ma.imperial.ac.uk/src/contrib
# or 
cannot open: HTTP status was '407 Proxy Authentication Required'

Many thanks,

Upvotes: 6

Views: 29614

Answers (5)

Cristian Chereji
Cristian Chereji

Reputation: 96

As Jeff Taylor wrote, R can indirectly make use of a proxy server. You need to specify the proxy server for both, http and https protocols, as follows:

$ export http_proxy=http://user:pass@proxy_server:port
$ export https_proxy=http://user:pass@proxy_server:port
$ R
> install.packages("<package_name>")

I just tested this solution and it works like a charm. The answer from Jeff was correct but unfortunatelly for most cases incomplete, as most of the servers are nowadays accesible over https.

Upvotes: 1

Viacheslav
Viacheslav

Reputation: 26

I tried to install swirl package, and had the same problem - proxy with authorisation.

After some experiments i found decision. May be my answer will help for anybody. On Windows 7 :

  1. set 1 or more (if ou need) env variables http_proxy (https_proxy and ftp_proxy if you need) (If you dont know how - read there http://www.computerhope.com/issues/ch000549.htm ) Its look like that env variables for proxy

  2. format http_proxy="http://Proxyusername:ProxyUserPassw@proxyServName:ProxyPort"

  3. Use '@' instead of %40

  4. In RStudio Tools->Global Options->Packages release check box "Use Internet Explorer library /proxy for HTTP"

Upvotes: 1

Jeff Taylor
Jeff Taylor

Reputation: 471

+1 for Juba, above. This worked for me:

$ export http_proxy=http://username:[email protected]:80
$ R
> install.packages("quantmod")

Upvotes: 2

James
James

Reputation: 66834

As @juba states, I think you want to set the http_proxy. From ?download.file:

Usernames and passwords can be set for HTTP proxy transfers via environment variable http_proxy_user in the form user:passwd. Alternatively, http_proxy can be of the form "http://user:[email protected]:8080/"

So, try: Sys.setenv(http_proxy="http://MyLoGiN:MyPaSs@1ncproxy1:80")

Be aware though:

These environment variables must be set before the download code is first used: they cannot be altered later by calling Sys.setenv.

So you are best off calling it in your .Rprofile

Upvotes: 3

Dirk is no longer here
Dirk is no longer here

Reputation: 368231

You are probably on Windows, so I would advice you to check the 'R on Windows FAQ' that came with your installation, particularly Question 2.19: The Internet download functions fail. You may need to restart R with the --internet2 option (IIRC) for the proxy settings to come into effect.

I always found this very cumbersome. An alternative is to install a proxy-aware webdownloader as eg wget (as a windows binary) where you set the proxy options in a file in your home directory. This is all from memory, I think the last time I was faced with such a proxy was in 2005 so YMMV.

Upvotes: 3

Related Questions