Bug 17323 - download.file(method = "curl", cacheOK = FALSE) fails on Windows
Summary: download.file(method = "curl", cacheOK = FALSE) fails on Windows
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R-devel (trunk)
Hardware: Other Other
: P5 minor
Assignee: R-core
Depends on:
Reported: 2017-08-04 18:04 UTC by Kevin Ushey
Modified: 2018-09-20 19:09 UTC (History)
2 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Ushey 2017-08-04 18:04:38 UTC
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()`.
Comment 1 Kevin Ushey 2017-08-04 18:07:51 UTC
Candidate fix:

Index: src/library/utils/R/windows/download.file.R
--- 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 = " "),
Comment 2 Ken Williams 2018-09-20 17:18:22 UTC
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.
Comment 3 Martin Maechler 2018-09-20 19:09:50 UTC
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.