Configuring R to Use an HTTP or HTTPS Proxy

Follow

If your networking environment requires outbound network connections to go through a HTTP or HTTPS proxy, you should configure R to use the proxy for all downloads.

The R documentation for the download.file method explains how to configure R to use an HTTP or HTTPS proxy. In short this requires adding one or more environment variables to your installation to point to the proxy.

To set the required environment variables you should add them to the R environment file (which is read by R at startup). On RStudio Workbench (previously RStudio Server Pro) and RStudio Server Open Source, this file is found at R_HOME/etc/Renviron.site. On RStudio Desktop, this file is found in the user home directory at ~/.Renviron. You can easily access your .Renviron file by running the command file.edit('~/.Renviron') within RStudio

Note that these files might not exist in the default installation of R so you may need to create them if they aren't already present.

Example environment file entries for proxy configuration might be:

http_proxy=http://proxy.dom.com/
http_proxy_user=user:passwd

https_proxy=https://proxy.dom.com/
https_proxy_user=user:passwd

Note that the http_proxy_user or https_proxy_user entries need only be supplied if the proxy requires authentication. There is also an ftp_proxy entry which can be specified for FTP transfers. You can consult the download.file documentation for detailed information on all available proxy options.

The names of the environment variables are case sensitive. Use the lowercase versions (i.e. http_proxy, not HTTP_PROXY). While it is legal to use the uppercase version, R checks the lowercase version first and may not check the uppercase version at all in some circumstances.

These environment variables are read once during the first call to download.file so if you have running R sessions you'll need to quit and restart them for the proxy behavior to take effect.

To see diagnostic information for HTTP transfers you can set the internet.info option to 0 or 1 (the default is 2, which only shows diagnostics for failure cases). For example:

options(internet.info = 0)

Comments