Proxy setting for R

R

R Problem Overview


I am facing problem while conecting R with internet in my office. May be this due to LAN settings. I tried the almost all possible ways I come across in the web (see below) but still in vain.

  • Method1: Invoking R using --internet2

  • Method2: Invoking R by setting ~/Rgui.exe http_proxy=http:/999.99.99.99:8080/ http_proxy_user=ask

  • Method3: Setting Setinternet2=TRUE

  • Method4:

      curl <- getCurlHandle()
      curlSetOpt(.opts = list(proxy = '999.99.99.99:8080'), curl = curl)
      Res <- getURL('http://www.cricinfo.com', curl = curl)
    

In above all methods I can able to load packages directly from CRAN also able to download files using download.file command

But using getURL(RCurl), readHTMLTable(XML), htmlTreeParse(XML) commands I am unable to extract web data. I am getting ~<HEAD>\n<TITLE>Access Denied</TITLE>\n</HEAD>~ error.

How to set LAN proxy settings for XML package in R?

R Solutions


Solution 1 - R

On Mac OS, I found the best solution here. Quoting the author, two simple steps are:

  1. Open Terminal and do the following:

    export http_proxy=http://staff-proxy.ul.ie:8080 export HTTP_PROXY=http://staff-proxy.ul.ie:8080

  2. Run R and do the following:

    Sys.setenv(http_proxy="http://staff-proxy.ul.ie:8080";)

double-check this with:

Sys.getenv("http_proxy")

I am behind university proxy, and this solution worked perfectly. The major issue is to export the items in Terminal before running R, both in upper- and lower-case.

Solution 2 - R

The problem is with your curl options – the RCurl package doesn't seem to use internet2.dll. You need to specify the port separately, and will probably need to give your user login details as network credentials, e.g.,

opts <- list(
  proxy         = "999.999.999.999", 
  proxyusername = "mydomain\\myusername", 
  proxypassword = "mypassword", 
  proxyport     = 8080
)
getURL("http://stackoverflow.com", .opts = opts)

Remember to escape any backslashes in your password. You may also need to wrap the URL in a call to curlEscape.

Solution 3 - R

For RStudio just you have to do this:

Firstly, open RStudio like always, select from the top menu:

Tools-Global Options-Packages

Uncheck the option: Use Internet Explorer library/proxy for HTTP

And then close the Rstudio, furthermore you have to:

  1. Find the file (.Renviron) in your computer, most probably you would find it here: C:\Users\your user name\Documents. Note that if it does not exist you can creat it just by writing this command in RStudio:

     file.edit('~/.Renviron')
    
  2. Add these two lines to the initials of the file:

     options(internet.info = 0)
    
     http_proxy="http://user_id:password@your_proxy:your_port"
    

And that's it..??!!!

Solution 4 - R

I had the same problem at my office and I solved it adding the proxy in the destination of the R shortcut; clik on right button of the R icon, preferences, and in the destination field add

"C:\Program Files\R\your_R_version\bin\Rgui.exe" http_proxy=http://user_id:passwod@your_proxy:your_port/

Be sure to put the directory where you have the R program installed. That works for me. Hope this help.

Solution 5 - R

This post pertains to R proxy issues on *nix. You should know that R has many libraries/methods to fetch data over internet.

For 'curl', 'libcurl', 'wget' etc, just do the following:

  1. Open a terminal. Type the following command:

    sudo gedit /etc/R/Renviron.site
    
  2. Enter the following lines:

    http_proxy='http://username:[email protected]:port/'
    https_proxy='https://username:[email protected]:port/'
    

Replace username, password, abc.com, xyz.com and port with these settings specific to your network.

  1. Quit R and launch again.

This should solve your problem with 'libcurl' and 'curl' method. However, I have not tried it with 'httr'. One way to do that with 'httr' only for that session is as follows:

library(httr)
set_config(use_proxy(url="abc.com",port=8080, username="username", password="password"))

You need to substitute settings specific to your n/w in relevant fields.

Solution 6 - R

Inspired by all the responses related on the internet, finally I've found the solution to correctly configure the Proxy for R and Rstudio.

There are several steps to follow, perhaps some of the steps are useless, but the combination works!

  1. Add environment variables http_proxy and https_proxy with proxy details.

     variable name: http_proxy
     variable value: https://user_id:password@your_proxy:your_port/
    
     variable name: https_proxy
     variable value: https:// user_id:password@your_proxy:your_port
    
  2. If you start R from a desktop icon, you can add the --internet flag to the target line (right click -> Properties)

e.g."C:\Program Files\R\R-2.8.1\bin\Rgui.exe" --internet2

  1. For RStudio just you have to do this:

Firstly, open RStudio like always, select from the top menu:

Tools-Global Options-Packages

Uncheck the option: Use Internet Explorer library/proxy for HTTP

  1. Find the file (.Renviron) in your computer, most probably you would find it here: C:\Users\your user name\Documents.

    Note that: if it does not exist you can create it just by writing this command in R:

     file.edit('~/.Renviron')
    

    Then add these six lines to the initials of the file:

     options(internet.info = 0)
    
     http_proxy = https:// user_id:password@your_proxy:your_port
    
     http_proxy_user = user_id:password
    
     https_proxy = https:// user_id:password0@your_proxy:your_port
    
     https_proxy_user = user_id:password
    
     ftp_proxy = user_id:password@your_proxy:your_port
    
  2. Restart R. Type the following commands in R to assure that the configuration above works well:

     Sys.getenv("http_proxy")
    
     Sys.getenv("http_proxy_user")
    
     Sys.getenv("https_proxy")
    
     Sys.getenv("https_proxy_user")
    
     Sys.getenv("ftp_proxy")
    
  3. Now you can install the packages as you want by using the command like:

     install.packages("mlr",method="libcurl")
    

    It's important to add method="libcurl", otherwise it won't work.

Solution 7 - R

If you start R from a desktop icon, you can add the --internet flag to the target line (right click -> Properties) e.g.

"C:\Program Files\R\R-2.8.1\bin\Rgui.exe" --internet2 

Solution 8 - R

On Windows 7 I solved this by going into my environment settings (try this link for how) and adding user variables http_proxy and https_proxy with my proxy details.

Solution 9 - R

Simplest way to get everything working in RStudio under Windows 10:

Open up Internet Explorer, select Internet Options:

enter image description here


Open editor for Environment variables:

enter image description here


Add a variable HTTP_PROXY in form:

HTTP_PROXY=http://username:password@localhost:port/

Example:

HTTP_PROXY=http://John:JohnPassword@localhost:8080/    

enter image description here


RStudio should work:

enter image description here

Solution 10 - R

Tried all of these and also the solutions using netsh, winhttp etc. Geek On Acid's answer helped me download packages from the server but none of these solutions worked for using the package I wanted to run (twitteR package).

The best solution is to use a software that let's you configure system-wide proxy.

FreeCap (free) and Proxifier (trial) worked perfectly for me at my company.

Please note that you need to remove proxy settings from your browser and any other apps that you have configured to use proxy as these tools provide system-wide proxy for all network traffic from your computer.

Solution 11 - R

My solution on a Windows 7 (32bit). R version 3.0.2

Sys.setenv(http_proxy="http://proxy.*_add_your_proxy_here_*:8080")

setInternt2

updateR(2)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAVSureshView Question on Stackoverflow
Solution 1 - RGeek On AcidView Answer on Stackoverflow
Solution 2 - RRichie CottonView Answer on Stackoverflow
Solution 3 - REliasView Answer on Stackoverflow
Solution 4 - RManuel RamónView Answer on Stackoverflow
Solution 5 - RadityakaranView Answer on Stackoverflow
Solution 6 - RMina HEView Answer on Stackoverflow
Solution 7 - RJackView Answer on Stackoverflow
Solution 8 - RjtromansView Answer on Stackoverflow
Solution 9 - RContangoView Answer on Stackoverflow
Solution 10 - RRishi DuaView Answer on Stackoverflow
Solution 11 - RDanView Answer on Stackoverflow