我正在尝试让R(在Windows上运行)从Internet下载一些软件包,但下载失败,因为我无法正确使用必要的代理服务器。尝试Windows菜单选项包>时的输出文本安装软件包...... 并选择一个CRAN镜像:
> 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
环境变量设置为:
ask
user:passwd
我是否以正确的方式使用正确的命令?
答案 0 :(得分:20)
您有两种选择:
编辑:一个诀窍是,在一个会话中尝试后,你不能在1和2之间改变主意,即如果你运行命令setInternet2(TRUE)并尝试使用它,例如install.packages('reshape2'),如果失败,则不能再调用setInternet2(FALSE)。您必须重新启动R会话。
从R版本3.2.0开始,setInternet2
功能可以设置互联网连接设置并在同一个R会话中更改它们。无需重启。
使用选项2时,指定用户名和密码的一种方式(很好且紧凑)是http_proxy =“http:// user:password@proxy.example.com:8080 /”
过去,我在选项2中获得了最多的运气
答案 1 :(得分:4)
如果您希望每次使用R时都使用Internet2,您可以将以下行添加到Rprofile.site文件中,该文件位于R.x.x \ etc \ Rprofile.site
utils::setInternet2(TRUE)
答案 2 :(得分:-2)
install.packages( “RCurl”)
这将解决您的问题。