Resolution tiers, tried in order: built-in DB -> user cache -> local
file -> CKAN datastore -> direct download URL -> ArcGIS layer ->
error. Supports fuzzy matching: morie_load_dataset("cpads_2021")
resolves to ocp21.
Arguments
- key
Dataset catalog key (or fuzzy match).
- db_path
Optional path to a SQLite/DuckDB file (default backend).
- refresh
If
TRUE, bypass the built-in database and the user cache (and, for remotely-backed datasets, the local file) and re-fetch from the remote source, overwriting the cached copy. Use this to pick up time-to-time updates to a dataset.- con
Optional pre-opened DBI connection for the user cache (overrides
db_path). The built-in DB read is always SQLite-based and is unaffected bycon.
Examples
# \donttest{
if (morie_has("sql")) withAutoprint({
# CPADS 2021-2022: downloaded once from open.canada.ca (39 MB), then a local
# read; try() so a missing optional backend does not fail the check
df <- try(morie_load_dataset("ocp21"))
# re-fetch from the portal to pick up an upstream revision (network):
# df <- morie_load_dataset("ocp21", refresh = TRUE)
# PostgreSQL cache (run a server first):
# con <- DBI::dbConnect(RPostgres::Postgres(),
# host = "localhost", dbname = "morie", user = "...")
# df <- morie_load_dataset("ocp21", con = con)
})
#> > df <- try(morie_load_dataset("ocp21"))
#> Fetching ocp21 from CKAN ...
#> Fetching ocp21 from CKAN (resource d2639429-c304-45a6-90b3-770562f4d46d)
#> Downloading https://open.canada.ca/data/dataset/736fa9b2-62e4-4e31-aea4-51869605b363/resource/d2639429-c304-45a6-90b3-770562f4d46d/download/cpads-2021-2022-pumf2.csv (live, then the Wayback Machine snapshot if the portal is down)
# }
