Skip to content

cderv/proxyconfig

Repository files navigation

proxyconfig

Azure pipelines build status Azure pipelines test status Azure pipelines coverage status Lifecycle: experimental CRAN status License: MIT Travis build status Codecov test coverage

The goal of proxyconfig is to help setting the proxy interactively.

About proxy configuration

Why would you need to configure a proxy ?

In a corporate environment, there is often a proxy you need to pass through to escape your company network. When behind this firewall of your company, you need to first tell R that it needs to pass the proxy before trying to reach the url and not to use it when the url you want to access are inside the same network.

Examples of when it is needed

For example, behind a company proxy,

  • install.package won’t be able to reach a cran mirror that is outside like https://https://cloud.r-project.org/
  • download.file won’t be able to get a file from a url
  • httr::GET, curl::curl won’t be able to be used for web url.

The first two are R base features and have a method argument that you can use to help configure correctly. Different methods can have different settings. The most used is libcurl that is also used by httr and curl 📦.

Some words about proxy configuration in R

Sometimes, proxy is automatically picked up by R. It is the case on windows where R uses the wininet method by default, for which the ‘Internet Options’, from Internet Explorer or Edge, are used for proxy configuration. On other system, proxy must often be explicity configured.

You’ll find information about Setting Proxies in R in the utils::download.file() help page: help("download.file", package = "utils") or ?download.file.

Installation

Currently, this package is only available on Github in development version :

# install.packages("devtools")
devtools::install_github("cderv/proxyconfig")

or using

source("https://install-github.me/cderv/proxyconfig")

How to use proxyconfig

How to set the proxy

Given a proxy url, you can set the proxy interactively using set_proxy using proxy argument. Proxy url must be of the form scheme://hostname[:port].

proxyconfig::set_proxy(proxy = "http://proxy.mycompany.com:3939")

You can also use options(proxyconfig.proxy = "http://proxy.mycompany.com:3939") so that it knows which url to use as default. You can use usethis::edit_r_profile() to open the user .Rprofile and add the option.

Then when in .Rprofile, you can call directly

proxyconfig::set_proxy()

By default if username and password not provided, this will prompt the user for authentification. You can pass them in set_proxy argument too to use non-interactively. This is not advice to pass them in clear in a script - this is what the interactive mode with dialog box aims to prevent.

If you don’t have any authentification for your proxy, use empty values explicitly.

proxyconfig::set_proxy(proxy = "http://proxy.mycompany.com:3939", username = "", password = "")

To prevent the proxy to be used for url on internal network domain, use noproxy argument. (empty by default). This useful for a github entreprise server or an internal cran repos for example, respectively on https://github.mycompany.com and https://cran.mycompany.com. Both are on the same domain - noproxy is configured here to look for url on domain mycompany.com without exiting the internal pany network through the proxy.

proxyconfig::set_proxy(proxy = "http://proxy.mycompany.com:3939", noproxy = ".mycompany.com")

If several domains (or IP addresses) are necessary, they will be concatenated properly.

proxyconfig::set_proxy(proxy = "http://proxy.mycompany.com:3939", noproxy = c(".mycompany.com", "163.104.50.180"))

How to check what is configured ?

set_proxy() will set the correct environment variable for the current session. You can verify if a proxy is currently configured with is_proxy_activated()

proxyconfig::is_proxy_activated()

You can have more information using verbose = TRUE. (Note that authentification is hidden when printed)

proxyconfig::is_proxy_activated(TRUE)

What if a proxy is already set ?

If a proxy is already set, set_proxy will issue a warning (and return false invisibly)

(proxyconfig::set_proxy(proxy =  "https://newproxy.company.com"))

You can unset a proxy configuration with unset_proxy()

proxyconfig::unset_proxy(verbose = TRUE)
# proxy is correctly deactivated
proxyconfig::is_proxy_activated(TRUE)

TODO

This is a very new package that works for me. Among the ideas I have for improvement

  • Use an option mechanism to make the proxy url persistent across sessions
  • Use keyring to store and retrieve auth accross session
  • Make a templating system to use proxyconfig in an internal package. Inspiration ghentr and pkgconfig
  • Improve console output with cli
  • Create an add-on for better interactation (and keybinding)

About

Tools to Configure Proxy Interactively

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages