Installing packages on RStudio Connect from behind a proxy

Follow

 

If your system is behind an HTTP proxy then additional configuration may be required for your RStudio Connect system to connect to CRAN or other servers needed to install packages. The required configuration varies depending on what type of HTTP connection you are making to the server. Without this configuration (or if this is incorrectly configured) you may see an error like

"Failed to retrieve package sources ...(internet connectivity issue?)"


The easiest option, in this case, is to configure RStudio Connect to use your outbound proxy during package installation. To do so, you'll want to modify the RStudio Connect configuration file:

/etc/rstudio-connect/rstudio-connect.gcfg

[Packages]
HTTPSProxy = https://username:password@proxy.example.com:1080/

 

The admin guide has further detailsBe sure to restart RStudio Connect after making these changes.
 
Alternatives

If you prefer, you can configure the outbound HTTP proxy settings in R instead of in RStudio Connect. You may wish to do this if you use R on the server for other tasks unrelated to RStudio Connect. 

HTTP Proxy Environment Variable

The most straightforward way to specify a proxy in R for rcurl and curl connections is to set the http_proxy environment variable. 

For example, you could add the following code to the /R_HOME/etc/Rprofile.site file so it applies to all users:

Sys.setenv(http_proxy = "http://proxy.example.com")

Proxy settings can include a host-name, port, and username/password if necessary. The following are all valid values for the http_proxy environment variable:

http://proxy.example.com/

http://proxy.example.com:1080/

http://username:password@proxy.example.com:1080/

Setting RCurl Proxy Options

The default HTTP connection type is rcurl. If you need more configurability than offered by the http_proxy environment variable you can specify RCurl proxy options explicitly using RCurlOptions. For example, you could add the following code to the .Rprofile for the rstudio-connect user:

options(RCurlOptions = list(proxy = "http://proxy.example.com")

You can set any underling curl option using this mechanism. To do this you translate curl options to lowercase and remove the CURL_ prefix (for example, CURLOPT_PROXYPORT becomes proxyport).

A list of available curl options can be found here: curl http proxy options.

 

Comments