knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  warning = FALSE,
  message = FALSE
)

Some resources from the City of Toronto Open Data Portal are ZIP files containing multiple files. When a resource like this is retrieved using get_resource(), the result is a list with elements named after each file.

For example, the dataset on the Annual Summary of Reportable Communicable Diseases:

library(opendatatoronto)
library(dplyr)

summary_diseases <- search_packages("Annual Summary of Reportable Communicable Diseases") %>%
  list_package_resources() %>%
  filter(name == "summary-of-reportable-communicable-diseases-in-toronto-2007-2017") %>%
  get_resource()

str(summary_diseases, max.level = 1)

To access a single file, you can pull out the element by name:

summary_diseases[["RatesbyDisease2007_2017.csv"]]


sharlagelfand/opendatatoronto documentation built on April 12, 2025, 7:52 p.m.