R 的代理设置
我在办公室将 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 数据。我收到 ~\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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
在 Mac OS 上,我在此处找到了最佳解决方案。引用作者的话,两个简单的步骤是:
1)打开终端并执行以下操作:
2)运行 R 并执行以下操作:
仔细检查:
我支持大学代理,并且此解决方案运行良好。主要问题是在运行 R 之前导出终端中的项目(大小写)。
On Mac OS, I found the best solution here. Quoting the author, two simple steps are:
1) Open Terminal and do the following:
2) Run R and do the following:
double-check this with:
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.
对于 RStudio,您只需执行以下操作:
首先,像往常一样打开 RStudio,从顶部菜单中选择:
工具-全局 选项-Packages
取消选中选项:使用 Internet Explorer 库/代理进行 HTTP
然后关闭 Rstudio,此外您还必须:
在计算机中找到文件 (.Renviron),你很可能会找到它此处:C:\Users\您的用户名\Documents。请注意,如果它不存在,您只需在 RStudio 中编写以下命令即可创建它:
将这两行添加到文件的首字母缩写中:
就这样..??!!!
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:
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:
Add these two lines to the initials of the file:
And that's it..??!!!
问题出在你的curl选项上——
RCurl
包似乎没有使用internet2.dll
。您需要单独指定端口,并且可能需要提供用户登录详细信息作为网络凭据,例如,
请记住转义密码中的任何反斜杠。您可能还需要将 URL 包装在对
curlEscape
的调用中。The problem is with your curl options – the
RCurl
package doesn't seem to useinternet2.dll
.You need to specify the port separately, and will probably need to give your user login details as network credentials, e.g.,
Remember to escape any backslashes in your password. You may also need to wrap the URL in a call to
curlEscape
.我在办公室遇到了同样的问题,我在 R 快捷方式的目标中添加代理解决了这个问题;单击 R 图标的右键、首选项,然后在目标字段中添加
确保将安装 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
Be sure to put the directory where you have the R program installed. That works for me. Hope this help.
这篇文章涉及 *nix 上的 R 代理问题。您应该知道 R 有许多库/方法可以通过互联网获取数据。
对于“curl”、“libcurl”、“wget”等,只需执行以下操作:
打开终端。键入以下命令:
输入以下行:
替换
用户名
、密码
、abc.com
、xyz.com
和端口 为您的网络特定的设置。
退出 R 并再次启动。
这应该可以使用“libcurl”和“curl”方法解决您的问题。但是,我还没有尝试过“httr”。仅针对该会话使用“httr”执行此操作的一种方法如下:
您需要在相关字段中替换特定于您的 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:
Open a terminal. Type the following command:
Enter the following lines:
Replace
username
,password
,abc.com
,xyz.com
andport
with these settings specific to your network.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:
You need to substitute settings specific to your n/w in relevant fields.
受到互联网上所有相关回复的启发,我终于找到了正确配置 R 和 Rstudio 代理的解决方案。
有几个步骤需要遵循,也许有些步骤是无用的,但是组合起来就有效了!
添加环境变量
http_proxy
和https_proxy
以及代理详细信息。如果从桌面图标启动 R,可以将
--internet
标志添加到目标行(右键单击 -> 属性)eg
"C:\Program Files\R\R-2.8.1\bin\Rgui.exe" --internet2
对于RStudio 只是你必须这样做:
首先,像往常一样打开 RStudio,从顶部菜单中选择:
工具-全局选项-包
取消选中选项:使用 Internet Explorer 库/代理进行 HTTP
在您的计算机中查找文件 (
.Renviron
),您很可能会在此处找到它:C:\Users\您的用户名\文档
。请注意:如果它不存在,您只需在 R 中编写此命令即可创建它:
然后将这六行添加到文件的首字母中:
Restart R。 在 R 中键入以下命令以确保上面的配置效果很好:
现在您可以使用以下命令根据需要安装软件包:
添加
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!
Add environment variables
http_proxy
andhttps_proxy
with proxy details.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
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
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:
Then add these six lines to the initials of the file:
Restart R. Type the following commands in R to assure that the configuration above works well:
Now you can install the packages as you want by using the command like:
It's important to add
method="libcurl"
, otherwise it won't work.在 Windows 7 上,我通过进入环境设置解决了这个问题(尝试此链接了解具体方法)并添加用户变量
http_proxy
和https_proxy
以及我的代理详细信息。On Windows 7 I solved this by going into my environment settings (try this link for how) and adding user variables
http_proxy
andhttps_proxy
with my proxy details.如果您从桌面图标启动 R,您可以将
--internet
标志添加到目标行(右键单击 -> 属性),例如If you start R from a desktop icon, you can add the
--internet
flag to the target line (right click -> Properties) e.g.在
Windows 10
下让 RStudio 一切工作的最简单方法:打开 Internet Explorer,选择
Internet 选项
:打开环境变量编辑器:
<一个href="https://i.sstatic.net/gNAdi.png" rel="nofollow noreferrer">
在表单中添加变量 HTTP_PROXY:
示例:
RStudio 应该可以工作:
Simplest way to get everything working in RStudio under
Windows 10
:Open up Internet Explorer, select
Internet Options
:Open editor for Environment variables:
Add a variable HTTP_PROXY in form:
Example:
RStudio should work:
尝试了所有这些以及使用 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.
Renviron.site
Renviron.site
->它应该有效:)R.home("home")
Renviron.site
in your R homeRenviron.site
in its home -> it should work :)我在 Windows 7(32 位)上的解决方案。 R版本3.0.2
My solution on a Windows 7 (32bit). R version 3.0.2