2011-01-28 21 views
19

我试图让R(在Windows上运行)从Internet下载一些软件包,但下载失败,因为我无法正确使用必要的代理服务器。输出文本,当我尝试在Windows菜单选项>安装包(S)...并选择CRAN镜是:如何告诉R解释器如何使用代理服务器?

> utils:::menuInstallPkgs()
--- Please select a CRAN mirror for use in this session ---
Warning: unable to access index for repository http://cran.opensourceresources.org/bin/windows/contrib/2.12
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.12
Error in install.packages(NULL, .libPaths()[1L], dependencies = NA, type = type) :
        no packages were specified
In addition: Warning message:
In open.connection(con, "r") :
        cannot open: HTTP status was '407 Proxy Authentication Required'

我知道代理的地址和端口,我也知道自动配置脚本的地址。我不知道什么是身份验证,但是在使用代理(在浏览器和其他应用程序中)时,我会在弹出的对话框中输入用户名和密码。

要设置代理,我试图每个以下的:

  • Sys.setenv(http_proxy="http://proxy.example.com:8080")
  • Sys.setenv("http_proxy"="http://proxy.example.com:8080")
  • Sys.setenv(HTTP_PROXY="http://proxy.example.com:8080")
  • Sys.setenv("HTTP_PROXY"="http://proxy.example.com:8080")

对于验证,我同样尝试设置http_proxy_user环境变量BLE到:

  • ask
  • user:passwd
  • 离开它触及

我在用正确的方式正确的命令?

+1

看起来不错。你是否也尝试使用--internet2选项来启动R(在Windows上,我假设?)? – 2011-01-28 20:15:13

+0

@Dirk E .:是的;我检查并发现我运行R的开始菜单快捷方式设置为使用`--internet2`选项。 (是的,它是在Windows上;我现在编辑了这个问题来说明问题。) – Firefeather 2011-01-28 20:21:38

回答

20

你有两个选择:

  1. 使用--internet2或setInternet2(TRUE),并设置在控制面板中的代理服务器的详细信息,在Internet选项
  2. 不要使用任何--internet2或setInternet2( FALSE),但指定的环境变量

编辑:一个技巧是,你不能改变1和2之间你的头脑,你已经在为尝试后,例如,如果你运行setInternet2(TRUE)命令并尝试使用它,例如安装。包('reshape2'),如果失败,则不能再调用setInternet2(FALSE)。您必须重新启动R会话。

从R版本3.2.0起,setInternet2函数可以设置互联网连接设置并在同一个R会话中更改它们。无需重启。


当使用选项2,一种方式(这是很好的和紧凑的)来指定的用户名和口令是HTTP_PROXY = “HTTP://用户:[email protected]:8080 /”

在过去,我选择了2

4

如果您希望在每次使用R时都使用internet2,则可以将以下行添加到位于Rxx \ etc \ Rprofile中的Rprofile.site文件.site

utils::setInternet2(TRUE) 
-2

install.packages(“RCurl”)

这将解决您的问题。

0

我想,所以如果我跑我的代码,我有这样的错误运行中的R此HTTPS链接:

R = GET( “https://wxs.ign.fr/7sngjsx2h6rl603ngqdx4phc/geoportail/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=BDCARTO_BDD_WLD_WGS84G:zone_occupation_sol&maxFeatures=1&Bbox=1.02,42.9,1.02,42.9”,配置(用户名= “hetraie”,密码= “hetraie”))

错误卷曲:: curl_fetch_memory(URL,手柄=手柄): 无法解析主机:wxs.ign.fr

我不知道我能做做解决这个亲blem。

相关问题