R - Using R with a proxy

If you have a proxy in your organization in order to connect to the internet, you might need to modify some parameters so that R can also access the internet. R use the default environment variables to work with a proxy:

  • HTTP_PROXY: The complete address of the proxy, ex: The proxy is used to connect to the internet
  • HTTPS_PROXY: Same as above but for https protocol. Usually it is the same address.
  • NO_PROXY: The list of urls that won't use the proxy. If you need to access another machine inside the platform, the url or ip must be listed here. If you use ip address, you can use the wildcard * (ex: 192.168.25.*), if you use an url, you must write the full url between the https:// and the next /.

If you want to change any of these variable, you can use the "Settings" button inside Saagie Data Fabric. It will be updated for any new jobs launched inside capsules.

For the notebooks, you need to restart the docker container before the changes are applied. If you don't want to restart it, you can use the following R code to change it instantly:

# List of exceptions to add
ips <- c('192.168.25.*', '1-random-dockerurl.public.saagie.com')

sapply(ips, function(ip) {                                                   # For each ip in the list
   if(!stringi::stri_detect_fixed(Sys.getenv('NO_PROXY'), ip)) {             # If the variable is not already present
       Sys.setenv('NO_PROXY'=paste(Sys.getenv('NO_PROXY'),ip, sep = ','))}}) # Add it to the existing environment variable

You will need to execute this every time you restart your notebook (.ipynb).