Convenience wrapper that loads the bundled report links, optionally filters
by fiscal year, and downloads reports as PDF, HTML, or both. Use
format = "metadata" to export a CSV of report metadata without
downloading any files.
Usage
auto_download(
format = NULL,
year = NULL,
download_dir = "gao_reports",
sleep_time = 1,
confirm = TRUE
)Arguments
- format
Character.
"pdf","html","both", or"metadata"."metadata"writes a CSV of report metadata without downloading files.NULL(default) prompts interactively; in non-interactive sessions defaults to"pdf".- year
Integer vector of 4-digit fiscal years, e.g.
2024or2020:2024.NULL(default) prompts interactively; in non-interactive sessions uses all available years.- download_dir
Character. Base directory for downloads.
pdf/and/orhtml/subdirectories are created beneath it.- sleep_time
Numeric. Seconds to pause between downloads.
- confirm
Logical. If
TRUE(default), prompts for confirmation before downloading. In non-interactive sessions,confirm = TRUEraises an error to prevent accidental mass downloads — setconfirm = FALSEexplicitly.
Value
For "pdf", "html", or "both": invisible character vector of
downloaded file paths. For "metadata": invisible path to the written CSV.
Details
PDF URLs are constructed directly from report IDs (e.g.,
/products/gao-24-106198 becomes /assets/gao-24-106198.pdf) rather than
scraping each report page, so no extra HTTP requests are needed for
link extraction.
Examples
if (FALSE) { # \dontrun{
# Interactive: walks through prompts
auto_download()
# Non-interactive: download 2024 PDFs
auto_download(format = "pdf", year = 2024, confirm = FALSE)
# Export metadata only (no file downloads)
auto_download(format = "metadata", year = 2020:2024, confirm = FALSE)
} # }
