Skip to contents

Phase 3EEE4. Single entry point that dispatches to the right loader function for any of the ~550 datasets in morie_dataset_portal_catalog(). Lets callers say morie_datasets_load_by_key("vpd_crime") or morie_datasets_load_by_key("hub:b4d0...assault") without remembering whether the relevant loader is morie_datasets_vpd_crime() or morie_datasets_tps_arcgis_hub_by_id().

Usage

morie_datasets_load_by_key(
  dataset_key,
  offline = TRUE,
  max_features = NULL,
  mode = c("auto", "soda2", "soda3", "odata"),
  app_token = NULL,
  source = NULL
)

Arguments

dataset_key

A dataset_key from morie_dataset_portal_catalog().

offline

If TRUE (default), prefer bundled fixtures. FALSE forces live mode for loaders that support it.

max_features

Optional row cap forwarded to the underlying loader.

mode

One of "auto" (default), "soda2", "soda3", "odata". Only honoured for Socrata-backed sources (chicago / nyc_nypd / nyc_opendata) that have a per-wrapper mode argument. "auto" lets each underlying loader pick its native default (soda2 today). 3FFF2.

app_token

Optional Socrata application token forwarded to SODA3-capable loaders. 3FFF2.

source

Optional portal disambiguator (e.g., "vancouver_opendata" vs "toronto_opendata") used when the dataset_key collides across portals. 3HHH5. Omit when the key is unique (the common case); pass when an ambiguous-key error is raised to pick the intended portal.

Value

A data.frame (or, for StatCan, the WDS metadata list).

Details

Resolution rules:

Bundled-fixture loaders

If the catalog's loader column names a function that takes no required arguments beyond optionally offline/max_features, that function is called directly with offline = offline + max_features.

Generic CKAN dispatchers

For Ontario / Montreal / Toronto CKAN catalog entries whose loader is the generic morie_datasets_*_ckan_resource(), the id (CKAN package_name slug) is resolved to a primary resource via package_show + first CSV resource, then fetched.

Generic ArcGIS Hub dispatcher

For TPS Hub entries (source == "tps_arcgis_hub"), the bare hub_id is passed to morie_datasets_tps_arcgis_hub_by_id().

StatCan WDS

For statcan_ccjs entries, returns the cube metadata via morie_datasets_statcan_cube_metadata().

Vancouver Opendatasoft

For vancouver_opendata entries beyond the 9 bundled fixtures, dispatches to morie_datasets_vancouver_opendata_by_id().

For datasets where the catalog only knows a key + portal (no row-level fixture, no targeted wrapper), live = FALSE raises a clear error pointing at the right live-mode dispatcher.

Examples

# All three calls below resolve to bundled offline fixtures (no
# network). The first call warms the cross-portal catalog cache
# (~2.8s); subsequent calls reuse it (<0.1s each).
df1 <- morie_datasets_load_by_key("vpd_crime")           # 550 rows
df2 <- morie_datasets_load_by_key("nypd_arrests_ytd")    # 5 rows
df3 <- morie_datasets_load_by_key("assault")             # 5 rows
c(vpd = nrow(df1), nypd = nrow(df2), tps_assault = nrow(df3))
#>         vpd        nypd tps_assault 
#>         550           5           5