How to install R packages via proxy [user + password]

前端 未结 5 591
-上瘾入骨i
-上瘾入骨i 2020-12-17 03:43

I need authentication to use internet, say these are my variables:

  1. Proxy : 1ncproxy1
  2. Port : 80
  3. Loggin : MyLoGiN
  4. Pass : MyPaSs
  5. <
相关标签:
5条回答
  • 2020-12-17 03:49

    +1 for Juba, above. This worked for me:

    $ export http_proxy=http://username:password@the-proxy.mycompany.com:80
    $ R
    > install.packages("quantmod")
    
    0 讨论(0)
  • 2020-12-17 03:55

    I tried to install swirl package, and had the same problem - proxy with authorisation.

    After some experiments i found decision. May be my answer will help for anybody. On Windows 7 :

    1. set 1 or more (if ou need) env variables http_proxy (https_proxy and ftp_proxy if you need) (If you dont know how - read there http://www.computerhope.com/issues/ch000549.htm ) Its look like that env variables for proxy

    2. format http_proxy="http://Proxyusername:ProxyUserPassw@proxyServName:ProxyPort"

    3. Use '@' instead of %40

    4. In RStudio Tools->Global Options->Packages release check box "Use Internet Explorer library /proxy for HTTP"

    0 讨论(0)
  • 2020-12-17 03:57

    As Jeff Taylor wrote, R can indirectly make use of a proxy server. You need to specify the proxy server for both, http and https protocols, as follows:

    $ export http_proxy=http://user:pass@proxy_server:port
    $ export https_proxy=http://user:pass@proxy_server:port
    $ R
    > install.packages("<package_name>")
    

    I just tested this solution and it works like a charm. The answer from Jeff was correct but unfortunatelly for most cases incomplete, as most of the servers are nowadays accesible over https.

    0 讨论(0)
  • 2020-12-17 04:11

    You are probably on Windows, so I would advice you to check the 'R on Windows FAQ' that came with your installation, particularly Question 2.19: The Internet download functions fail. You may need to restart R with the --internet2 option (IIRC) for the proxy settings to come into effect.

    I always found this very cumbersome. An alternative is to install a proxy-aware webdownloader as eg wget (as a windows binary) where you set the proxy options in a file in your home directory. This is all from memory, I think the last time I was faced with such a proxy was in 2005 so YMMV.

    0 讨论(0)
  • 2020-12-17 04:15

    As @juba states, I think you want to set the http_proxy. From ?download.file:

    Usernames and passwords can be set for HTTP proxy transfers via environment variable http_proxy_user in the form user:passwd. Alternatively, http_proxy can be of the form "http://user:pass@proxy.dom.com:8080/"

    So, try: Sys.setenv(http_proxy="http://MyLoGiN:MyPaSs@1ncproxy1:80")

    Be aware though:

    These environment variables must be set before the download code is first used: they cannot be altered later by calling Sys.setenv.

    So you are best off calling it in your .Rprofile

    0 讨论(0)
提交回复
热议问题