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: 2017-08-04 18:07 UTC (History)
0 users

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 = " "),