Downloads to a temporary name next to the destination and moves the file into place only once it has been received and checked, so that an interrupted run leaves no truncated file that a later run would take for a complete one.
download_file()applies any check;download_pdf()checks the PDF signature, since some links return a web page (error or landing page) with status 200;is_pdf_file()is that check.
Arguments
- url
Character. The URL.
- dest
Character. Destination path; its folder is created if needed.
- pause
Numeric. Minimum seconds between two requests to this site.
- check
Function of a file path returning
TRUEorFALSE, orNULL.- check_failure
Character. Reason recorded when the check fails.
- ...
Other arguments of
polite_request().- path
Character. A file on disk.
Value
download_file() and download_pdf(): TRUE if the file was saved,
FALSE otherwise; last_failure() then gives the reason. An existing
file is replaced only by a file that passed the check. is_pdf_file():
TRUE or FALSE.
See also
Other downloads:
queue_downloads()
Examples
f <- tempfile(fileext = ".pdf")
writeLines("<html>not found</html>", f)
is_pdf_file(f)
#> [1] FALSE
if (FALSE) { # \dontrun{
options(politecollect.user_agent = "my_project (me@example.org)")
if (!download_pdf("https://www.bis.org/review/r240101a.pdf", "r240101a.pdf")) {
last_failure()
}
} # }