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{
# CPADS 2021-2022 (default DuckDB cache); try() so a transient
# upstream outage does not fail the check
df <- try(morie_load_dataset("ocp21"))
#> Fetching ocp21 from the CKAN datastore ...
#> Fetching from CKAN datastore: resource_id=d2639429-c304-45a6-90b3-770562f4d46d
#> Warning: cannot open URL 'https://open.canada.ca/data/en/api/3/action/datastore_search?resource_id=d2639429-c304-45a6-90b3-770562f4d46d&limit=32000&offset=0': HTTP status was '500 Internal Server Error'
#> Error in readLines(url(api_url), warn = FALSE) :
#> cannot open the connection to 'https://open.canada.ca/data/en/api/3/action/datastore_search?resource_id=d2639429-c304-45a6-90b3-770562f4d46d&limit=32000&offset=0'
df <- try(morie_load_dataset("ocp21", refresh = TRUE)) # force re-fetch
#> Fetching ocp21 from the CKAN datastore ...
#> Fetching from CKAN datastore: resource_id=d2639429-c304-45a6-90b3-770562f4d46d
#> Warning: cannot open URL 'https://open.canada.ca/data/en/api/3/action/datastore_search?resource_id=d2639429-c304-45a6-90b3-770562f4d46d&limit=32000&offset=0': HTTP status was '500 Internal Server Error'
#> Error in readLines(url(api_url), warn = FALSE) :
#> cannot open the connection to 'https://open.canada.ca/data/en/api/3/action/datastore_search?resource_id=d2639429-c304-45a6-90b3-770562f4d46d&limit=32000&offset=0'
# PostgreSQL cache (run a server first):
# con <- DBI::dbConnect(RPostgres::Postgres(),
# host = "localhost", dbname = "morie", user = "...")
# df <- morie_load_dataset("ocp21", con = con)
# }
