From c2eb6ffab44188a455f079cc9ec7afc36eab2ad3 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Tue, 9 Mar 2021 10:03:01 -0600 Subject: [PATCH] fix yihui/tinytex#286: increase the timeout to 3600 seconds in download_file() --- NEWS.md | 4 ++++ R/io.R | 10 ++++++++++ man/download_file.Rd | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/NEWS.md b/NEWS.md index f769c9c..53e4dae 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,10 @@ - Added a new function `retry()` to retry calling a function for a number of times in case of errors. +## MINOR CHANGES + +- The `timeout` option in `options()` is set to 3600 seconds when it takes the default value of 60 seconds, which may not be enough for downloading large files (thanks, @matthewgson, yihui/tinytex#286). + # CHANGES IN xfun VERSION 0.21 ## NEW FEATURES diff --git a/R/io.R b/R/io.R index 396ebd1..c0e70b8 100644 --- a/R/io.R +++ b/R/io.R @@ -185,10 +185,20 @@ grep_sub = function(pattern, replacement, x, ...) { #' \code{\link{url_filename}()}. #' @param ... Other arguments to be passed to \code{\link{download.file}()} #' (except \code{method}). +#' @note To allow downloading large files, the \code{timeout} option in +#' \code{\link{options}()} will be temporarily set to one hour (3600 seconds) +#' inside this function when this option has the default value of 60 seconds. +#' If you want a different \code{timeout} value, you may set it via +#' \code{options(timeout = N)}, where \code{N} is the number of seconds (not +#' 60). #' @return The integer code \code{0} for success, or an error if none of the #' methods work. #' @export download_file = function(url, output = url_filename(url), ...) { + if (getOption('timeout') == 60L) { + opts = options(timeout = 3600) # one hour + on.exit(options(opts), add = TRUE) + } download = function(method = 'auto') download.file(url, output, ..., method = method) for (method in c(if (is_windows()) 'wininet', 'libcurl', 'auto')) { if (!inherits(try_silent(res <- download(method = method)), 'try-error') && res == 0) diff --git a/man/download_file.Rd b/man/download_file.Rd index 86b6635..f21edd9 100644 --- a/man/download_file.Rd +++ b/man/download_file.Rd @@ -26,3 +26,11 @@ method can succeed. The reason to enumerate all methods is that sometimes the default method does not work, e.g., \url{https://stat.ethz.ch/pipermail/r-devel/2016-June/072852.html}. } +\note{ +To allow downloading large files, the \code{timeout} option in + \code{\link{options}()} will be temporarily set to one hour (3600 seconds) + inside this function when this option has the default value of 60 seconds. + If you want a different \code{timeout} value, you may set it via + \code{options(timeout = N)}, where \code{N} is the number of seconds (not + 60). +}