Skip to content

Commit

Permalink
fix rstudio/tinytex#286: increase the timeout to 3600 seconds in down…
Browse files Browse the repository at this point in the history
…load_file()
  • Loading branch information
yihui committed Mar 9, 2021
1 parent b057fb0 commit c2eb6ff
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions R/io.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions man/download_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c2eb6ff

Please sign in to comment.