R 的代理设置

发布于 2024-11-16 21:41:57 字数 759 浏览 1 评论 0原文

我在办公室将 R 连接到互联网时遇到问题。这可能是由于 LAN 设置造成的。我尝试了在网络上遇到的几乎所有可能的方法(见下文),但仍然徒劳。

  • 方法1:使用--internet2调用R

  • 方法2:通过设置调用R~ /Rgui.exe http_proxy=http:/999.99.99.99:8080/ http_proxy_user=ask

  • 方法三:设置 Setinternet2=TRUE

  • 方法4:

    curl <- getCurlHandle()
    curlSetOpt(.opts = 列表(代理 = '999.99.99.99:8080'),curl = 卷曲)
    Res <- getURL('http://www.cricinfo.com',curl=curl)
    

在上述所有方法中,我可以直接从CRAN加载包,也可以使用download.file命令下载文件

,但是使用getURL(RCurl)readHTMLTable(XML)htmlTreeParse(XML) 命令我无法提取 Web 数据。我收到 ~\nAccess Denied\n~ 错误。

如何在 R 中为 XML 包设置 LAN 代理设置?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

没︽人懂的悲伤 2024-11-23 21:41:58

在 Mac OS 上,我在此处找到了最佳解决方案。引用作者的话,两个简单的步骤是:

1)打开终端并执行以下操作:

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

2)运行 R 并执行以下操作:

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

仔细检查:

Sys.getenv("http_proxy")

我支持大学代理,并且此解决方案运行良好。主要问题是在运行 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.

七婞 2024-11-23 21:41:58

对于 RStudio,您只需执行以下操作:

首先,像往常一样打开 RStudio,从顶部菜单中选择:

工具-全局 选项-Packages

取消选中选项:使用 Internet Explorer 库/代理进行 HTTP

然后关闭 Rstudio,此外您还必须:

  1. 在计算机中找到文件 (.Renviron),你很可能会找到它此处:C:\Users\您的用户名\Documents。请注意,如果它不存在,您只需在 RStudio 中编写以下命令即可创建它:

    file.edit('~/.Renviron')
    
  2. 将这两行添加到文件的首字母缩写中:

    选项(internet.info = 0)
    
    http_proxy =“http://user_id:password@your_proxy:your_port”
    

就这样..??!!!

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

只有一腔孤勇 2024-11-23 21:41:58

问题出在你的curl选项上——RCurl包似乎没有使用internet2.dll
您需要单独指定端口,并且可能需要提供用户登录详细信息作为网络凭据,例如,

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

请记住转义密码中的任何反斜杠。您可能还需要将 URL 包装在对 curlEscape 的调用中。

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.

戏舞 2024-11-23 21:41:58

我在办公室遇到了同样的问题,我在 R 快捷方式的目标中添加代理解决了这个问题;单击 R 图标的右键、首选项,然后在目标字段中添加

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

确保将安装 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.

ゃ懵逼小萝莉 2024-11-23 21:41:58

这篇文章涉及 *nix 上的 R 代理问题。您应该知道 R 有许多库/方法可以通过互联网获取数据。

对于“curl”、“libcurl”、“wget”等,只需执行以下操作:

  1. 打开终端。键入以下命令:

    sudo gedit /etc/R/Renviron.site
    
  2. 输入以下行:

    http_proxy='http://用户名:[电子邮件受保护]< /a>:端口/'
    https_proxy='https://用户名:[电子邮件受保护]:port/ '
    

    替换用户名密码abc.comxyz.com端口 为您的网络特定的设置。

  3. 退出 R 并再次启动。

这应该可以使用“libcurl”和“curl”方法解决您的问题。但是,我还没有尝试过“httr”。仅针对该会话使用“httr”执行此操作的一种方法如下:

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

您需要在相关字段中替换特定于您的 n/w 的设置。

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.

  3. 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.

回忆追雨的时光 2024-11-23 21:41:58

受到互联网上所有相关回复的启发,我终于找到了正确配置 R 和 Rstudio 代理的解决方案。

有几个步骤需要遵循,也许有些步骤是无用的,但是组合起来就有效了!

  1. 添加环境变量 http_proxyhttps_proxy 以及代理详细信息。

    变量名称:http_proxy
    变量值:https://user_id:password@your_proxy:your_port/
    
    变量名称:https_proxy
    变量值:https:// user_id:password@your_proxy:your_port
    
  2. 如果从桌面图标启动 R,可以将 --internet 标志添加到目标行(右键单击 -> 属性)

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

  3. 对于RStudio 只是你必须这样做:

    首先,像往常一样打开 RStudio,从顶部菜单中选择:

    工具-全局选项-包

    取消选中选项:使用 Internet Explorer 库/代理进行 HTTP

  4. 在您的计算机中查找文件 (.Renviron),您很可能会在此处找到它:C:\Users\您的用户名\文档

    请注意:如果它不存在,您只需在 R 中编写此命令即可创建它:

    file.edit('~/.Renviron')
    

    然后将这六行添加到文件的首字母中:

    选项(internet.info = 0)
    
    http_proxy = https:// user_id:password@your_proxy:your_port
    
    http_proxy_user = 用户 ID:密码
    
    https_proxy = https:// user_id:password0@your_proxy:your_port
    
    https_proxy_user = 用户 ID:密码
    
    ftp_proxy = 用户 ID:密码@您的代理:您的端口
    
  5. Restart R。 在 R 中键入以下命令以确保上面的配置效果很好:

    Sys.getenv("http_proxy")
    
    Sys.getenv("http_proxy_user")
    
    Sys.getenv("https_proxy")
    
    Sys.getenv("https_proxy_user")
    
    Sys.getenv("ftp_proxy")
    
  6. 现在您可以使用以下命令根据需要安装软件包:

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

    添加method="libcurl"很重要,否则它将无法工作。

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

  3. 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

  4. 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
    
  5. 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")
    
  6. 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.

信愁 2024-11-23 21:41:58

在 Windows 7 上,我通过进入环境设置解决了这个问题(尝试此链接了解具体方法)并添加用户变量 http_proxyhttps_proxy 以及我的代理详细信息。

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.

爱你是孤单的心事 2024-11-23 21:41:58

如果您从桌面图标启动 R,您可以将 --internet 标志添加到目标行(右键单击 -> 属性),例如

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

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 
半城柳色半声笛 2024-11-23 21:41:58

Windows 10 下让 RStudio 一切工作的最简单方法:

打开 Internet Explorer,选择 Internet 选项

在此处输入图像描述


打开环境变量编辑器:

<一个href="https://i.sstatic.net/gNAdi.png" rel="nofollow noreferrer">在此处输入图像描述


在表单中添加变量 HTTP_PROXY:

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

示例:

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

在此处输入图像描述


RStudio 应该可以工作:

在此处输入图像描述

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

呆萌少年 2024-11-23 21:41:58

尝试了所有这些以及使用 netsh、winhttp 等的解决方案。
Geek On Acid 的答案帮助我从服务器下载软件包,但这些解决方案都不适用于我想要运行的软件包(twitteR 软件包)。

最好的解决方案是使用可让您配置系统范围代理的软件。

FreeCap(免费)和 Proxifier(试用版)在我的公司非常适合我。

请注意,您需要从浏览器和已配置为使用代理的任何其他应用程序中删除代理设置,因为这些工具为来自您计算机的所有网络流量提供系统范围的代理。

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.

没︽人懂的悲伤 2024-11-23 21:41:58
  1. 使用 < 找到您的 R 主页代码>R.home("家")
  2. 添加以下内容行 到 R 主目录中的 Renviron.site
http_proxy=http://proxy.dom.com/
http_proxy_user=user:passwd

https_proxy=https://proxy.dom.com/
https_proxy_user=user:passwd
  1. 打开 R ->; R 在其 home 中读取 Renviron.site ->它应该有效:)
  1. Find your R home with R.home("home")
  2. Add following lines to Renviron.site in your R home
http_proxy=http://proxy.dom.com/
http_proxy_user=user:passwd

https_proxy=https://proxy.dom.com/
https_proxy_user=user:passwd
  1. Open R -> R reads Renviron.site in its home -> it should work :)
大姐,你呐 2024-11-23 21:41:58

我在 Windows 7(32 位)上的解决方案。 R版本3.0.2

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

setInternt2

updateR(2)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文