LifeLongStudent
LifeLongStudent

Reputation: 2468

no_proxy and http_proxy while installing R package

We have internal local cran mirror which does not need http_proxy to be used.

However for some packages there are third party dependencies which are downloaded from internet. Example stringi downloads something called [1]

So how to say to R to not to use proxy for getting internal mirror.

I tried following and it does not work.

Sys.setenv(http_proxy="http://proxydetails.com")
Sys.setenv(https_proxy="http://proxydetails.com")
Sys.setenv(HTTP_PROXY="http://proxydetails.com")
Sys.setenv(HTTPS_PROXY="http://proxydetails.com")
Sys.setenv(no_proxy='localmirror.com')

If I keep all of them then i get error [2] If I comment out http_proxy settings then it gives error [1]

[1] Error in download.file(paste(href, fname, sep = ""), outfname, mode = "wb"): cannot open URL 'http://static.rexamine.com/packages/icudt55l.zip'

[2] Error log

[cloud-user@rstudio-test2 ~]$ sudo ./install.sh [1] "stringi" [1] "Checking package stringi" Loading required package: stringi [1] "Installing package stringi" Warning: unable to access index for repository http://localmirror/src/contrib Warning messages: 1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘stringi’ 2: package ‘stringi’ is not available (for R version 3.1.2)

Upvotes: 1

Views: 1460

Answers (1)

CedricFch
CedricFch

Reputation: 66

I had the same issue and managed to solve it by setting two R options:

  • options(download.file.method="curl") : set R download method to curl

  • options(download.file.extra = paste0("--noproxy ", your_internal_cran_hostname)) : do not use proxy for this specific host

It seems like R default download method only supports no_proxy="*", which is why you have to use curl instead.

You can include these two lines in you R_HOME/etc/.Rprofile to make these changes persistent.

Hope this helps !

PS: if you want to remove red messages printed during download, you can add a "-s" option in download.file.extra

Upvotes: 2

Related Questions