opendatatoronto
is an R interface to the City of Toronto Open Data Portal. The goal of the package is to help read data directly into R without needing to manually download it via the portal.
In the portal, datasets are called packages. You can see a list of available packages by using list_packages()
. This will show metadata about the package, including what topics (i.e. tags) the package covers, a description of it, any civic issues it addresses, how many resources there are (and their formats), how often it is is refreshed and when it was last refreshed.
library(opendatatoronto)
packages <- list_packages(limit = 10)
packages
#> # A tibble: 10 x 11
#> title id topics civic_issues publisher excerpt dataset_category
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Cata… 473d… City … <NA> Informat… Histor… Table
#> 2 Lobb… 6a87… City … <NA> Lobbyist… The Lo… Document
#> 3 Addr… abed… Locat… Mobility Informat… This d… Document
#> 4 Prop… 1aca… Locat… Mobility Informat… This d… Document
#> 5 Buil… 108c… Devel… Affordable … Toronto … Provid… Document
#> 6 Buil… 8219… Devel… <NA> Toronto … Provid… Document
#> 7 Muni… 5da2… City … Affordable … Municipa… This d… Document
#> 8 Shor… fc41… Permi… Affordable … Municipa… This d… Table
#> 9 Poll… 7bce… City … <NA> City Cle… Polls … Table
#> 10 Dail… 8a6e… City … Affordable … Shelter,… Daily … Table
#> # … with 4 more variables: num_resources <int>, formats <chr>,
#> # refresh_rate <chr>, last_refreshed <date>
Or, you can search packages by title using search_packages()
:
apartment_packages <- search_packages("Apartment")
apartment_packages
#> # A tibble: 2 x 11
#> title id topics civic_issues publisher excerpt dataset_category
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Apar… 2b98… Busin… Affordable … Municipa… This d… Table
#> 2 Apar… 4ef8… Locat… Affordable … Municipa… This d… Table
#> # … with 4 more variables: num_resources <int>, formats <chr>,
#> # refresh_rate <chr>, last_refreshed <date>
You can also see metadata for one specific package using show_package()
:
show_package("996cfe8d-fb35-40ce-b569-698d51fc683b")
#> # A tibble: 1 x 11
#> title id topics civic_issues publisher excerpt dataset_category
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 TTC … 996c… <NA> <NA> <NA> <NA> <NA>
#> # … with 4 more variables: num_resources <int>, formats <chr>,
#> # refresh_rate <chr>, last_refreshed <date>
Within a package, there are a number of resources - e.g. CSV, XSLX, JSON, SHP files, and more. Resources are the actual “data”.
For a given package, you can get a list of resources using list_package_resources()
, either by using a package found via search_packages()
or list_packages()
:
apartment_building_registration_package <- search_packages("Apartment Building Registration")
apartment_building_registration_resources <- apartment_building_registration_package %>%
list_package_resources()
apartment_building_registration_resources
#> # A tibble: 1 x 4
#> name id format last_modified
#> <chr> <chr> <chr> <date>
#> 1 Apartment Building Registra… 3ad76a8c-0518-4df2-b94e-8c7… CSV 2021-01-06
or by passing the package’s portal URL directly:
list_package_resources("https://open.toronto.ca/dataset/apartment-building-registration/")
#> # A tibble: 1 x 4
#> name id format last_modified
#> <chr> <chr> <chr> <date>
#> 1 Apartment Building Registra… 3ad76a8c-0518-4df2-b94e-8c7… CSV 2021-01-06
Finally (and most usefully!), you can download the resource (i.e., the actual data) directly into R using get_resource()
:
apartment_building_registration_data <- apartment_building_registration_resources %>%
get_resource()
apartment_building_registration_data
#> # A tibble: 3,462 x 70
#> `_id` AIR_CONDITIONIN… AMENITIES_AVAIL… ANNUAL_FIRE_ALA… ANNUAL_FIRE_PUM…
#> <int> <chr> <chr> <chr> <chr>
#> 1 51801 NONE <NA> NO NO
#> 2 51802 NONE <NA> YES NO
#> 3 51803 <NA> <NA> <NA> <NA>
#> 4 51804 CENTRAL AIR <NA> YES YES
#> 5 51859 NONE <NA> YES YES
#> 6 48401 NONE <NA> YES YES
#> 7 48402 NONE Outdoor pool , … YES NO
#> 8 48403 NONE <NA> YES YES
#> 9 48404 CENTRAL AIR <NA> YES YES
#> 10 48405 NONE <NA> YES YES
#> # … with 3,452 more rows, and 65 more variables:
#> # APPROVED_FIRE_SAFETY_PLAN <chr>, BALCONIES <chr>,
#> # BARRIER_FREE_ACCESSIBILTY_ENTR <chr>, BIKE_PARKING <chr>,
#> # CONFIRMED_STOREYS <dbl>, CONFIRMED_UNITS <dbl>,
#> # DATE_OF_LAST_INSPECTION_BY_TSSA <chr>,
#> # DESCRIPTION_OF_CHILD_PLAY_AREA <chr>,
#> # DESCRIPTION_OF_INDOOR_EXERCISE_ROOM <chr>,
#> # DESCRIPTION_OF_OUTDOOR_REC_FACILITIES <chr>, ELEVATOR_PARTS_REPLACED <chr>,
#> # ELEVATOR_STATUS <chr>, EMERG_POWER_SUPPLY_TEST_RECORDS <chr>,
#> # EXTERIOR_FIRE_ESCAPE <chr>, FACILITIES_AVAILABLE <chr>, FIRE_ALARM <chr>,
#> # GARBAGE_CHUTES <chr>, GREEN_BIN_LOCATION <chr>,
#> # HEATING_EQUIPMENT_STATUS <chr>, HEATING_EQUIPMENT_YEAR_INSTALLED <chr>,
#> # HEATING_TYPE <chr>, INDOOR_GARBAGE_STORAGE_AREA <chr>, INTERCOM <chr>,
#> # IS_THERE_A_COOLING_ROOM <chr>, IS_THERE_EMERGENCY_POWER <chr>,
#> # LAUNDRY_ROOM <chr>, LAUNDRY_ROOM_HOURS_OF_OPERATION <chr>,
#> # LAUNDRY_ROOM_LOCATION <chr>, LOCKER_OR_STORAGE_ROOM <chr>,
#> # NO_BARRIER_FREE_ACCESSBLE_UNITS <chr>,
#> # NO_OF_ACCESSIBLE_PARKING_SPACES <chr>, NO_OF_ELEVATORS <chr>,
#> # NO_OF_LAUNDRY_ROOM_MACHINES <chr>, NON_SMOKING_BUILDING <chr>,
#> # OUTDOOR_GARBAGE_STORAGE_AREA <chr>, PARKING_TYPE <chr>, PCODE <chr>,
#> # PET_RESTRICTIONS <chr>, PETS_ALLOWED <chr>,
#> # PROP_MANAGEMENT_COMPANY_NAME <chr>, PROPERTY_TYPE <chr>,
#> # RECYCLING_BINS_LOCATION <chr>, RSN <dbl>,
#> # SEPARATE_GAS_METERS_EACH_UNIT <chr>, SEPARATE_HYDRO_METER_EACH_UNIT <chr>,
#> # SEPARATE_WATER_METERS_EA_UNIT <chr>, SITE_ADDRESS <chr>,
#> # SPRINKLER_SYSTEM <chr>, SPRINKLER_SYSTEM_TEST_RECORD <chr>,
#> # SPRINKLER_SYSTEM_YEAR_INSTALLED <chr>, TSSA_TEST_RECORDS <chr>,
#> # VISITOR_PARKING <chr>, WARD <chr>, WINDOW_TYPE <chr>, YEAR_BUILT <chr>,
#> # YEAR_OF_REPLACEMENT <chr>, YEAR_REGISTERED <chr>, NO_OF_STOREYS <lgl>,
#> # `IS_THERE_EMERGENCY_POWER?` <lgl>, `NON-SMOKING_BUILDING` <lgl>,
#> # NO_OF_UNITS <lgl>, NO_OF_ACCESSIBLEPARKING_SPACES <lgl>,
#> # `FACILITIES_AVAILABLE?` <lgl>, `IS_THERE_A_COOLING_ROOM?` <lgl>,
#> # NO_BARRIERFREE_ACCESSBLE_UNITS <lgl>
The opendatatoronto
package can currently handle the download of CSV, XLS/XLSX, XML, JSON, SHP, and GeoJSON resources, as well as ZIP resources that contain multiple files. For more information, see the following vignettes: