Wrap an httr-Based R Call in a Proxy Configuration
Use httr's use_proxy and with_config to supply a proxy for a selected expression or an existing library call that uses httr.
For an R operation that uses httr, build its proxy configuration with use_proxy and apply it to the expression you want to run:
route <- httr::use_proxy('proxy.example', 8080)
result <- httr::with_config(route, {
httr::GET('https://www.example.com/')
})
For a proxy account, use_proxy also accepts username, password and auth arguments. Supply those from the application's existing credential configuration when required.
The expression can contain a higher-level library call when that library actually makes its requests through httr. A library based on RCurl or another HTTP client has its own configuration interface; identify that backend before choosing which object to pass.
with_config combines the supplied configuration with existing httr settings by default. For an allowed public-URL test, an address from the HTTP proxy list can fill use_proxy’s host and port only when the merged settings contain no proxy credentials. Its override argument selects whether the existing settings should instead be ignored for that expression.
This is a configuration scope for the selected code. set_config is the interface for changing httr's broader default configuration, so use the wrapper when the proxy is meant to accompany one operation.