Setting proxies for R

I encountered a problem while connecting R to the internet in my office. Perhaps this is due to the settings of the local network. I tried almost all the possible ways that I come across on the Internet (see below), but still in vain.

  • Method1: calling R using --internet2

  • Method 2: Call 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 the above all methods, I can download packages directly from CRAN, which can also download files using the download.file command

But using the getURL(RCurl) , readHTMLTable(XML) , htmlTreeParse(XML) , I cannot extract the web data. I get the error ~<HEAD>\n<TITLE>Access Denied</TITLE>\n</HEAD>~ .

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

+63
r
Jun 24 2018-11-11T00:
source share
11 answers

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

1) Open a 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:

 Sys.getenv("http_proxy") 

I am for a university proxy, and this solution worked perfectly. The main problem is to export elements in the terminal before starting R, both in upper and lower case.

+42
Nov 28 '11 at 2:56 a.m.
source share

The problem with your curl options is that the RCurl package does not seem to use internet2.dll . You need to specify the port separately, and probably you will need to specify your user data as network credentials, for example,

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

Remember to avoid any backslashes in your password. You may also need to wrap the url when calling curlEscape .

+22
Jun 24. '11 at 12:24
source share

For RStudio, you just have to do this:

First, open RStudio, as always, select from the top menu:

Tools - Global Options - Packages

Uncheck: Use Internet Explorer Library / Proxy for HTTP

And then close Rstudio, in addition, you need to:

  • Locate the file (.Renviron) on your computer, most likely you will find it here: C: \ Users \ your username \ Documents. Please note: if it does not exist, you can create it simply by writing this command to RStudio:

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

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

What is it..??!!!

+11
Jul 17 '15 at 11:36
source share

I had the same problem in my office and I decided that adding a proxy server to the R-label destination; clik on the 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 place the directory where the R program is installed. This is suitable for me. I hope for this help.

+9
Nov 02 '11 at 15:57
source share

In Windows 7, I solved this by going to my environment settings ( try this link for ) and add the user variables http_proxy and https_proxy with my proxy data.

+6
Aug 07 '13 at 16:54
source share

If you run R from the desktop icon, you can add the --internet flag to the target line (right-click β†’ Properties), for example.

 "C:\Program Files\R\R-2.8.1\bin\Rgui.exe" --internet2 
+5
05 Oct '12 at 6:14
source share

This post refers to R proxy server issues on * nix. You should know that R has many libraries / methods for receiving data over the Internet.

For "curl", "libcurl", "wget", etc. just follow these steps:

  • Open a terminal. Enter the following command:

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

     http_proxy='http://username:password@abc.com:port/' https_proxy='https://username:password@xyz.com:port/' 

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

  • Close R and run again.

This should solve your problem with the libcurl and curl methods. However, I have not tried it using "httr". One way to do this with "httr" is for this session only:

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

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

+5
Apr 24 '16 at 6:25
source share

Inspired by all the answers related to the Internet, I found a solution to correctly configure proxies for R and Rstudio. There are several steps, maybe some of these steps are useless, but the combination works!

  • Add the http_proxy and https_proxy environment variables with proxy data.

    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

  • If you run R from the desktop icon, you can add the -internet flag to the target line (right-click β†’ Properties)

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

  • For RStudio, you just need to do this:

    First, open RStudio, as always, select from the top menu:

    Tools-Global Options-Packages

    Uncheck: Use Internet Explorer Library / Proxy for HTTP

  • Locate the file (.Renviron) on your computer, most likely you will find it here: C: \ Users \ your username \ Documents. Note: if it does not exist, you can create it simply 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

  • Restart R. Enter the following commands in R to verify that the above configuration works well:

    Sys.getenv ("http_proxy")

    Sys.getenv ("http_proxy_user")

    Sys.getenv ("https_proxy")

    Sys.getenv ("https_proxy_user")

    Sys.getenv ("ftp_proxy")

  • Now you can install the packages as you like using the command:

    install.packages ("MLR", method = "Libcurl")

    It is important to add 'method = "libcurl"', otherwise it will not work.

+2
Oct. 14 '16 at 13:45
source share

The easiest way to get everything that works in RStudio under Windows 10 :

Open Internet Explorer, select Internet Options :

enter image description here




Open editor for environment variables:

enter image description here




Add the HTTP_PROXY variable in the 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

+1
Jun 02 '17 at 12:04 on
source share

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

The best solution is to use software that allows you to configure a proxy server for the entire system.

FreeCap (free) and Proxifier (trial version) worked fine for me in my company.

Please note that you need to remove the proxy server settings from your browser and any other applications that you have configured to use the proxy server, as these tools provide a proxy server for the entire system for all network traffic from your computer.

0
Jun 14 '13 at 2:52
source share

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

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

setInternt2

Updater (2)

0
Oct 31 '17 at 18:25
source share



All Articles