Proxy setting for R

2019-01-02 20:00发布

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
11条回答
唯独是你
2楼-- · 2019-01-02 20:07

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.

查看更多
骚的不知所云
3楼-- · 2019-01-02 20:09

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.

查看更多
公子世无双
4楼-- · 2019-01-02 20:09

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)
查看更多
只靠听说
5楼-- · 2019-01-02 20:11

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.

查看更多
何处买醉
6楼-- · 2019-01-02 20:12

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.

查看更多
还给你的自由
7楼-- · 2019-01-02 20:12

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..??!!!

查看更多
登录 后发表回答