R 的代理设置 [英] Proxy setting for R
问题描述
我在办公室将 R 与互联网连接时遇到问题.这可能是由于 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.
方法1:使用
--internet2
方法二:通过设置~/Rgui.exe http_proxy=http:/999.99.99.99:8080/http_proxy_user=ask
方法3:设置Setinternet2=TRUE
方法 4:
curl <- getCurlHandle()
curlSetOpt(.opts = list(proxy = '999.99.99.99:8080'), curl = curl)
Res <- getURL('http://www.cricinfo.com', curl = curl)
在上述所有方法中,我可以直接从 CRAN 加载包,也可以使用 download.file 命令下载文件
In above all methods I can able to load packages directly from CRAN also able to download files using download.file command
但是使用 getURL(RCurl)
、readHTMLTable(XML)
、htmlTreeParse(XML)
命令我无法提取网络数据.我收到 ~\n
错误.
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.
如何在 R 中为 XML 包设置 LAN 代理设置?
How to set LAN proxy settings for XML package in R?
推荐答案
在 Mac OS 上,我找到了最好的解决方案 此处.引用作者的话,两个简单的步骤是:
On Mac OS, I found the best solution here. Quoting the author, two simple steps are:
1) 打开终端并执行以下操作:
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) 运行 R 并执行以下操作:
2) Run R and do the following:
Sys.setenv(http_proxy="http://staff-proxy.ul.ie:8080")
再次检查:
Sys.getenv("http_proxy")
我支持大学代理,这个解决方案非常有效.主要问题是在运行 R 之前导出终端中的项目,包括大写和小写.
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.
这篇关于R 的代理设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!