I'm using R in a commercial environment where external connectivity all goes via a web proxy, so we need to specify the proxy server address and ensure we connect to it with Windows authentication.
I already have code that will configure the RCurl and httr packages to use those settings by default - i.e.
httr::set_config(config(
proxy = "my.proxy.address",
proxyuserpwd = ":",
proxyauth = 4
))
or
opts <- list(
proxy = "my.proxy.address",
proxyuserpwd = ":",
proxyauth = 4
)
RCurl::options(RCurlOptions = opts)
However, in a couple of cases recently, I've found packages that depend on the curl package to make web requests - for instance xml2::read_xml
- and I can't find any way to set the same proxy options so they're picked up by default and used by curl.
If I use curl directly myself, I can set the options on a new handle and the following code is sufficient to work successfully:
h = new_handle(proxy = "my.proxy.address",
proxyuserpwd = ":")
con = curl(url,handle = h)
page = xml2::read_xml(con)
... but this isn't any help when the use of curl is buried within someone else's function!
Alternatively, I know I can set up an environment variable for the proxy address, like this:
Sys.setenv(https_proxy = "https://my.proxy.address")
... and libcurl picks it up. But if I do just this, then I end up with an HTTP 407 proxy authentication error. Is there a way to specify blank username / password (as the proxyuserpwd setting does), so we authenticate with Windows credentials? It also doesn't seem possible to specify the proxyauth option as an environment variable.
Can anyone offer a solution or any suggestions, please?