Learn R Programming

pmlbr (version 0.2.3)

graceful_download: Download a File Gracefully with Retry Mechanism

Description

Attempts to download a file from a specified URL, retrying a set number of times if the download fails. This function meets CRAN's requirement for gracefully handling the use of internet resources by catching errors and returning a warning message if the download ultimately fails.

Usage

graceful_download(url, destfile, retries = 3)

Value

Logical. Returns `TRUE` if the download succeeds, `FALSE` otherwise.

Arguments

url

Character. The URL of the file to download.

destfile

Character. The path to the destination file where the downloaded content will be saved.

retries

Integer. The maximum number of download attempts (default is 3).

Examples

Run this code
if (FALSE) {
dataset_url <- "https://example.com/dataset.csv"
tmp <- tempfile(fileext = ".csv")
success <- download_file_gracefully(dataset_url, tmp)
if (!success) {
  message("Continuing gracefully without the dataset.")
}
}

Run the code above in your browser using DataLab