我如何告诉 R 解释器如何使用代理服务器? [英] How do I tell the R interpreter how to use the proxy server?
问题描述
我试图让 R(在 Windows 上运行)从 Internet 下载一些软件包,但下载失败,因为我无法正确使用必要的代理服务器.当我尝试 Windows 菜单选项 Packages > Install package(s)... 并选择 CRAN 镜像时的输出文本是:
I'm trying to get R (running on Windows) to download some packages from the Internet, but the download fails because I can't get it to correctly use the necessary proxy server. The output text when I try the Windows menu option Packages > Install package(s)... and select a CRAN mirror is:
<代码>>utils:::menuInstallPkgs()--- 请选择一个 CRAN 镜像在本次会话中使用---
警告:无法访问存储库索引 http://cran.opensourceresources.org/bin/windows/contrib/2.12
警告:无法访问存储库的索引 http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.12
install.packages 中的错误(NULL,.libPaths()[1L],dependencies = NA,type = type):
没有指定包
另外:警告信息:
在 open.connection(con, "r") 中:
无法打开:HTTP 状态为需要 407 代理身份验证"
我知道代理的地址和端口,我也知道自动配置脚本的地址.我不知道身份验证叫什么,但是在使用代理(在浏览器和其他一些应用程序中)时,我在弹出的对话框窗口中输入用户名和密码.
I know the address and port of the proxy, and I also know the address of the automatic configuration script. I don't know what the authentication is called, but when using the proxy (in a browser and some other applications), I enter a username and password in a dialog window that pops up.
为了设置代理,我尝试了以下各项:
To set the proxy, I tried each of the following:
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
环境变量设置为:
For authentication, I similarly tried setting the http_proxy_user
environment variable to:
询问
user:passwd
- 保持原样
我是否以正确的方式使用了正确的命令?
Am I using the right commands in the right way?
推荐答案
您有两个选择:
- 使用 --internet2 或 setInternet2(TRUE) 并在控制面板的 Internet 选项中设置代理详细信息
- 不要使用 --internet2 或 setInternet2(FALSE),而是指定环境变量
<小时>
一个技巧是,在会话中尝试过之后,您不能在 1 和 2 之间改变主意,即如果您运行命令 setInternet2(TRUE) 并尝试使用它,例如install.packages('reshape2'),如果失败,你就不能调用 setInternet2(FALSE).您必须重新启动 R 会话.
从 R 版本 3.2.0 开始,setInternet2
函数可以设置互联网连接设置并在同一个 R 会话中更改它们.无需重启.
As of R version 3.2.0, the setInternet2
function can set internet connection settings and change them within the same R session. No need to restart.
使用选项 2 时,指定用户名和密码的一种方式(既美观又紧凑)是 http_proxy="http://user:password@proxy.example.com:8080/"
When using option 2, one way (which is nice and compact) to specify the username and password is http_proxy="http://user:password@proxy.example.com:8080/"
过去,我最幸运的是选项 2
In the past, I have had most luck with option 2
这篇关于我如何告诉 R 解释器如何使用代理服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!