Skip to contents

Downloads a .ivt (or its containing .zip) from a resolved statcan_ivt_resolve_url() URL into the ivt cache and returns the local .ivt path. The payload is sniffed: a .zip is unzipped, a raw IVT is kept as-is.

Usage

statcan_ivt_download(
  download_url,
  key = NULL,
  dest_dir = NULL,
  overwrite = FALSE,
  quiet = FALSE
)

Arguments

download_url

A direct-download URL (a b2020 .zip or a Download.cfm?PID= endpoint), or a one-row statcan_ivt_catalogue() tibble (its download_url and, by default, its catalogue number as the cache key are used).

key

Cache key used to name the per-table folder under the ivt cache. Optional when download_url is a catalogue row (defaults to the row's catalogue number).

dest_dir

Directory the .ivt is written to. Defaults to a per-table folder under the ivt cache (ivt_cache_dir("ivt")); get_statcan_ivt() passes a temporary folder when keep_ivt = FALSE.

overwrite

Re-download even if a .ivt already exists.

quiet

Suppress the download message.

Value

Path to the local .ivt file, or NULL (invisibly, with a warning) if the endpoint could not be reached.

Examples

# Downloads from Statistics Canada. Returns NULL with a warning if offline
# (no error), so no try() is needed.
# \donttest{
url <- statcan_ivt_resolve_url("Alternative.cfm?PID=55701&EXT=IVT")
path <- statcan_ivt_download(url, key = "97-570-X1981004", dest_dir = tempdir())
# }