On my Windows 10 machine with a 'curl' binary on the PATH, the following download invocation prints an error and also sends the downloaded content to standard out, rather than the requested tempfile:
status <- download.file(
method = "curl",
cacheOK = FALSE,
destfile = tempfile()
I notice two issues:
1. 'curl' writes an error message of the form "curl: (6) Could not resolve host: no-cache'";
2. The output is written to standard output, rather than the requested temporary file.
I believe the issue here is that 'download.file()' contains a line of the form:
if (!cacheOK) extra <- c(extra, "-H 'Pragma: no-cache'")
but that attempt to use single quotes to quote an argument fails on Windows. The issue here would likely be resolved by using `shQuote()`.
--- src/library/utils/R/windows/download.file.R (revision 73035)
+++ src/library/utils/R/windows/download.file.R (working copy)
@@ -64,7 +64,7 @@
if(length(destfile) != 1L || typeof(url) != "character")
stop("'destfile' must be a length-one character vector");
if(quiet) extra <- c(extra, "-s -S")
- if(!cacheOK) extra <- c(extra, "-H 'Pragma: no-cache'")
+ if(!cacheOK) extra <- c(extra, paste("-H", shQuote("Pragma: no-cache")))
status <- system(paste("curl",
paste(extra, collapse = " "),
This fix would appear to solve the problem, would be great to get it applied.
The impact of this bug is that the 'curl' download method can't be used to install packages on Windows.
The reason is because `download.file` is hard-coded to use incorrect quoting on Windows (single quotes aren't valid in command calls) when `cacheOK` is FALSE, and `install.packages` is hard-coded to set `cacheOK=FALSE` for several of the things it's trying to download.
'curl' support is important to me because 'curl' supports supplying usernames & passwords in a ~/.netrc file (or ~/_netrc file on Windows), which we use to access a private repository of our own R packages.
Windows support is important to me because life isn't fair.
Thank you Kevin, for your report and patch,
and you Ken, for the confirmation that it solves the problem for you.
As I cannot imagine this change to be harmful in any case, I've committed it
(for both platforms --- one goal would be to get to one source definition instead of two separate ones) to R-devel (svn rev 75339) ... planning to port to R-patched eventually.