gpt4 book ai didi

r - 我如何告诉R解释器如何使用代理服务器?

转载 作者:行者123 更新时间:2023-12-03 11:56:52 25 4
gpt4 key购买 nike

我试图让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'



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

要设置代理,我尝试了以下每种方法:
  • 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
  • 保持不变

  • 我是否以正确的方式使用正确的命令?

    最佳答案

    您有两种选择:

  • 使用--internet2或setInternet2(TRUE)并在控制面板的Internet选项
  • 中设置代理详细信息
  • 不要使用--internet2或setInternet2(FALSE),而是指定环境变量


  • 编辑:一个技巧是,在 session 中尝试过之后,您无法在1和2之间改变主意,即如果您运行命令setInternet2(TRUE)并尝试使用它,例如install.packages('reshape2'),如果失败,则无法调用setInternet2(FALSE)。您必须重新启动R session 。

    从R版本3.2.0开始, setInternet2函数可以设置Internet连接设置并在同一R session 中更改它们。无需重启。

    使用选项2时,一种指定用户名和密码的方法(简洁实用)是http_proxy =“http:// user:password@proxy.example.com:8080 /”

    过去,我对选项2的运气最大

    关于r - 我如何告诉R解释器如何使用代理服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4832560/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com