Skip to contents

Fetch data from the CKAN API and cache it

Usage

morie_fetch_ckan(
  dataset_key = "cpads",
  limit = Inf,
  db_path = NULL,
  resource_id = NULL,
  con = NULL,
  portal = NULL
)

Arguments

dataset_key

One of "cpads", "csads", "csus".

limit

Maximum records to fetch. The CKAN datastore caps a single request at 32000 rows, so larger resources are paged through with offset; the default reads the entire resource.

db_path

Optional override for the database path.

resource_id

Optional CKAN datastore resource id. When supplied (e.g. from morie_dataset_catalog()$ckan_resource_id) it is used directly, so any catalogued dataset can be fetched without a built-in database; dataset_key then only labels the cache table.

con

Optional pre-opened DBI connection (overrides db_path).

portal

Optional CKAN portal base URL (e.g. "https://data.ontario.ca"); the default is open.canada.ca. The catalog gives it for resources on another portal.

Value

A data.frame.

Examples

# \donttest{
# Requires network access. Fetches the first 200 rows of the
# Canadian Postsecondary Alcohol and Drug Use Survey from the
# Government of Canada CKAN datastore:
cpads <- morie_fetch_ckan(dataset_key = "cpads", limit = 200L)
#> Fetching cpads from CKAN (resource d2639429-c304-45a6-90b3-770562f4d46d)
nrow(cpads)
#> [1] 200
# }