Dispatch to download_spei(), download_eddi(), or download_usdm().
The selected function validates its arguments, constructs download URLs,
and handles previews, downloads, optional extraction, and return values.
Usage
download_drought(
source = c("spei", "eddi", "usdm"),
date = c("2020-01-01", "2020-12-31"),
timescale = 1L,
directory_to_save = NULL,
acknowledgement = FALSE,
hash = FALSE,
show_progress = TRUE,
max_tries = 3L,
rate_limit = 2,
unzip = TRUE,
remove_zip = FALSE,
download = TRUE,
remove_command = FALSE,
version = c("2.11", "2.10", "legacy"),
...
)Arguments
- source
character(1).
"spei"(default),"eddi", or"usdm". Usesbase::match.arg(), allowing unambiguous partial matches.- date
character(1 or 2). One date or inclusive range endpoints in
"YYYY-MM-DD"format, in either order. EDDI and USDM select Tuesdays within the interval and stop if none occur. Default isc("2020-01-01", "2020-12-31"). Ignored for SPEI, which downloads a complete multi-year file.- timescale
integer(1). Positive accumulation timescale in months, used by SPEI and EDDI. Default is
1L. Ignored for USDM. Input validation does not establish whether the provider has a file for that timescale.- directory_to_save
character(1). Non-empty output directory. SPEI and EDDI save files directly here. USDM uses
zip_files/for archives anddata_files/for extracted files beneath this directory.- acknowledgement
logical(1). Must be
TRUEto proceed, including for previews. Downloads and extracted files may require substantial storage. Default isFALSE.- hash
logical(1). Return a combined MD5 hash of the output directory instead of the download summary. Uses
directory_to_savefor SPEI/EDDI anddata_files/for USDM, including existing files. Default isFALSE; ignored whendownload = FALSE.- show_progress
logical(1). Show per-file messages and download progress bars during sequential downloads. Default is
TRUE. Ignored during concurrent downloads, where per-file progress is disabled. Status and summary messages may still be printed whenFALSE.- max_tries
integer(1). Maximum attempts per file request, including the initial attempt. Must be at least 1. Default is
3L.- rate_limit
numeric(1). Request-throttling interval in seconds. Default is 2. Passed unchanged to
download_run_method()for sequential downloads. For concurrent downloads, multiplied by the configured daemon count for the"default"compute profile before being passed to each worker.- unzip
logical(1). Extract USDM archives into
data_files/. Default isTRUE. Ignored for SPEI and EDDI.- remove_zip
logical(1). Remove USDM archives and their
zip_files/directory recursively after extraction, including remaining contents. Requiresunzip = TRUEfor USDM. Default isFALSE. Ignored for SPEI and EDDI.- download
logical(1). Deprecated.
FALSEwarns and returns a preview after directory creation, without making network requests. Default isTRUE.- remove_command
logical(1). Deprecated and ignored;
TRUEwarns. No command file is generated. Default isFALSE.- version
character(1). SPEI selection:
"2.11"(default),"2.10", or"legacy". The last choice uses the unversioned/files/endpoint; its release is not identified by the URL. Usesbase::match.arg(). No automatic fallback between versions occurs. Ignored for EDDI and USDM.- ...
Additional arguments forwarded to the selected source function. Its
...argument is currently reserved and ignored.
Value
The selected source function's result, with visibility preserved:
With
download = FALSE, an invisible list containingurls,destfiles, andn_files.With
download = TRUEandhash = FALSE, an invisible download summary containingsuccess,failed,skipped,failed_urls, andfailed_files. The two failure vectors arecharacter(0)when no downloads failed, including when every file was skipped.With
download = TRUEandhash = TRUE, a visible character scalar containing the combined MD5 hash of the source's output directory.
Counts describe file downloads, not extraction or scientific validity. Validation or extraction failures can prevent a normal return.
Details
Only arguments relevant to the selected source are forwarded. Common validation occurs once in the source function; this wrapper does not repeat validation, directory creation, or download execution.
Previews create the output directories but make no network requests.
They include existing destination files. Actual downloads use
download_run(), which skips existing non-empty files and reports
individual failures. See the source functions for endpoint limitations
and extraction behavior.
SPEI retains the flat speiNN.nc filename across versions for compatibility
with process_drought(). Existing-file checks do not distinguish versions.
The date argument does not subset SPEI downloads; temporal selection is
performed during processing.
Note
No authentication is required. SPEI and EDDI provide raster inputs; USDM provides polygon inputs for the downstream drought workflow.
Concurrent downloads
File downloads use configured daemons in the "default" compute profile,
or run sequentially when that profile has no configured daemons.
Daemon creation and shutdown are managed by the caller using
mirai::daemons(). For concurrent downloads, configure a fixed local pool
with mirai::daemons(n, .compute = "default") before calling this function.
Daemon detection, counting, and task dispatch always use the "default"
compute profile, regardless of the active profile. Daemon counting and rate
scaling assume that the pool still contains the n workers configured by
that call, with no workers added separately or pool resizing during
downloads. Each worker receives one URL/destination pair per task; the
remaining request arguments are constant across tasks.
Source-specific validation, URL discovery, archive extraction, and directory hashing run in the calling process. Only file downloads are dispatched to workers.
Examples
if (FALSE) { # \dontrun{
download_drought(
source = "spei",
timescale = 1L,
version = "2.11",
directory_to_save = "./data/drought",
acknowledgement = TRUE
)
download_drought(
source = "usdm",
date = c("2020-01-07", "2020-03-31"),
directory_to_save = "./data/drought",
acknowledgement = TRUE
)
} # }