| Title: | Access the 'City of Vancouver' Open Data API |
|---|---|
| Description: | Wrapper around the 'City of Vancouver' Open Data API <https://opendata.vancouver.ca/api/v2/console> to simplify and standardize access to 'City of Vancouver' open data. Functionality to list the data catalogue and access data and geographic records. |
| Authors: | Jens von Bergmann [aut, cre] |
| Maintainer: | Jens von Bergmann <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.9 |
| Built: | 2026-05-14 09:55:05 UTC |
| Source: | https://github.com/mountainmath/vancouvr |
Sends a server-side aggregation query to the CoV Open Data API and returns the result as a tibble. Because aggregation is performed by the API, this is suitable for summarising large datasets without downloading all records.
Results are cached for the duration of the R session.
aggregate_cov_data( dataset_id, select = "count(*) as count", group_by = NULL, where = NULL, apikey = getOption("VancouverOpenDataApiKey"), refresh = FALSE )aggregate_cov_data( dataset_id, select = "count(*) as count", group_by = NULL, where = NULL, apikey = getOption("VancouverOpenDataApiKey"), refresh = FALSE )
dataset_id |
Dataset id from the Vancouver Open Data catalogue |
select |
Aggregation expression using ODSQL syntax. Default '"count(*) as count"'. |
group_by |
Grouping expression using ODSQL syntax. Default 'NULL' (no grouping). |
where |
Filter expression using ODSQL syntax. Default 'NULL' (no filter). |
apikey |
Vancouver Open Data API key, default 'getOption("VancouverOpenDataApiKey")' |
refresh |
Bypass the session cache and re-download, default 'FALSE' |
A tibble with one row per group, with columns named according to the 'select' expression.
[get_cov_data()] to download full or filtered records, [search_cov_datasets()] to find dataset IDs
## Not run: # Count of each ticket status for fire hydrant infractions aggregate_cov_data("parking-tickets-2017-2019", group_by = "status", where = "infractiontext LIKE 'FIRE'") # Sum land and building values by tax year (server-side, no full download needed) aggregate_cov_data("property-tax-report", select = "sum(current_land_value) as Land, sum(current_improvement_value) as Building", group_by = "tax_assessment_year") ## End(Not run)## Not run: # Count of each ticket status for fire hydrant infractions aggregate_cov_data("parking-tickets-2017-2019", group_by = "status", where = "infractiontext LIKE 'FIRE'") # Sum land and building values by tax year (server-side, no full download needed) aggregate_cov_data("property-tax-report", select = "sum(current_land_value) as Land, sum(current_improvement_value) as Building", group_by = "tax_assessment_year") ## End(Not run)
Downloads a dataset and returns it as a tibble or 'sf' object. When 'cast_types = TRUE' (the default), field types are looked up via [get_cov_metadata()] and columns are automatically cast to integer, numeric, or Date. Datasets containing a 'geo_shape' field are returned as an 'sf' object; if spatial conversion fails a plain tibble is returned with a warning.
Results are cached for the duration of the R session, keyed on all query parameters. Re-running the same call does not trigger a second download.
get_cov_data( dataset_id, select = "*", where = NULL, apikey = getOption("VancouverOpenDataApiKey"), rows = NULL, cast_types = TRUE, refresh = FALSE, ... )get_cov_data( dataset_id, select = "*", where = NULL, apikey = getOption("VancouverOpenDataApiKey"), rows = NULL, cast_types = TRUE, refresh = FALSE, ... )
dataset_id |
Dataset id from the Vancouver Open Data catalogue |
select |
Column selection / expression string using ODSQL syntax, e.g. '"current_land_value, land_coordinate as coord"'. Default '"*"' returns all columns. |
where |
Filter expression using ODSQL syntax, e.g. ‘"tax_assessment_year=’2024' AND zoning_district LIKE 'RS-'"'. Default 'NULL' returns all rows. |
apikey |
Vancouver Open Data API key, default 'getOption("VancouverOpenDataApiKey")' |
rows |
Maximum number of rows to return. Default 'NULL' returns all rows. |
cast_types |
Logical; use metadata to auto-cast column types and convert spatial datasets to 'sf'. Default 'TRUE'. |
refresh |
Bypass the session cache and re-download, default 'FALSE' |
... |
Ignored; retained for compatibility with earlier versions |
A tibble, or an 'sf' object when the dataset has a 'geo_shape' field and 'cast_types = TRUE'.
[get_cov_metadata()] for field names and types, [aggregate_cov_data()] for server-side aggregation, [search_cov_datasets()] to find dataset IDs
## Not run: # Filtered download: parking tickets on one block get_cov_data("parking-tickets-2017-2019", where = "block = 1100 AND street = 'ALBERNI ST'") # Select specific columns and limit rows (useful for exploration) get_cov_data("property-tax-report", select = "tax_assessment_year, current_land_value, zoning_district", where = "tax_assessment_year = '2024'", rows = 100) # Spatial dataset: returned automatically as an sf object property_polygons <- get_cov_data("property-parcel-polygons") class(property_polygons) # "sf" "data.frame" ## End(Not run)## Not run: # Filtered download: parking tickets on one block get_cov_data("parking-tickets-2017-2019", where = "block = 1100 AND street = 'ALBERNI ST'") # Select specific columns and limit rows (useful for exploration) get_cov_data("property-tax-report", select = "tax_assessment_year, current_land_value, zoning_district", where = "tax_assessment_year = '2024'", rows = 100) # Spatial dataset: returned automatically as an sf object property_polygons <- get_cov_data("property-parcel-polygons") class(property_polygons) # "sf" "data.frame" ## End(Not run)
Returns a tibble describing each field in the dataset, including its API name, data type, display label, and description. Results are cached for the duration of the R session.
This function is called internally by [get_cov_data()] when 'cast_types = TRUE' to determine column types and identify spatial fields.
get_cov_metadata( dataset_id, apikey = getOption("VancouverOpenDataApiKey"), refresh = FALSE )get_cov_metadata( dataset_id, apikey = getOption("VancouverOpenDataApiKey"), refresh = FALSE )
dataset_id |
the CoV open data dataset id |
apikey |
the CoV open data API key, optional |
refresh |
Bypass the session cache and re-download, default 'FALSE' |
A tibble with one row per field and columns:
Field name as used in 'where' and 'select' queries
API data type (e.g. '"text"', '"int"', '"double"', '"date"', '"geo_shape"')
Human-readable display label
Field description, if provided by the portal
[get_cov_data()], [list_cov_datasets()]
## Not run: # View all fields in the street trees dataset get_cov_metadata("street-trees") # Find which fields are spatial get_cov_metadata("property-parcel-polygons") |> dplyr::filter(type == "geo_shape") ## End(Not run)## Not run: # View all fields in the street trees dataset get_cov_metadata("street-trees") # Find which fields are spatial get_cov_metadata("property-parcel-polygons") |> dplyr::filter(type == "geo_shape") ## End(Not run)
Fetches the full City of Vancouver Open Data catalogue and returns it as a tibble. Results are cached for the duration of the R session; subsequent calls return the cached copy unless 'refresh = TRUE'.
list_cov_datasets( trim = TRUE, apikey = getOption("VancouverOpenDataApiKey"), refresh = FALSE )list_cov_datasets( trim = TRUE, apikey = getOption("VancouverOpenDataApiKey"), refresh = FALSE )
trim |
Remove columns that are entirely 'NA', default 'TRUE' |
apikey |
the CoV open data API key, optional |
refresh |
Bypass the session cache and re-download, default 'FALSE' |
A tibble with one row per dataset. The first four columns are always 'dataset_id', 'title', 'keyword', and 'search-term'; remaining columns contain catalogue metadata (trimmed to non-empty columns when 'trim = TRUE').
[search_cov_datasets()] to filter the catalogue by a search term, [get_cov_data()] to download a specific dataset
## Not run: list_cov_datasets() ## End(Not run)## Not run: list_cov_datasets() ## End(Not run)
Filters the City of Vancouver Open Data catalogue for datasets whose title, dataset ID, keyword, or search-term fields match 'search_term' (using 'grepl()', so regular expressions are supported). When no exact match is found, a fuzzy-match hint list of similarly named datasets is printed.
search_cov_datasets( search_term, trim = TRUE, apikey = getOption("VancouverOpenDataApiKey"), refresh = FALSE )search_cov_datasets( search_term, trim = TRUE, apikey = getOption("VancouverOpenDataApiKey"), refresh = FALSE )
search_term |
A grep-compatible string to search through dataset titles, IDs, keywords, and search terms |
trim |
Remove columns that are entirely 'NA', default 'TRUE' |
apikey |
the CoV open data API key, optional |
refresh |
Bypass the session cache and re-download, default 'FALSE' |
A tibble with one row per matching dataset, in the same format as [list_cov_datasets()].
[list_cov_datasets()] to retrieve the full catalogue, [get_cov_data()] to download a specific dataset
## Not run: # Search using a plain string search_cov_datasets("trees") # Search using a regular expression search_cov_datasets("parking.*(2019|2020)") ## End(Not run)## Not run: # Search using a plain string search_cov_datasets("trees") # Search using a regular expression search_cov_datasets("parking.*(2019|2020)") ## End(Not run)