Retrieving multi-file ZIP resources

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)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

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)
#> List of 6
#>  $ ChickenpoxAgegroups2017.csv             :Classes 'tbl_df', 'tbl' and 'data.frame':    3 obs. of  14 variables:
#>  $ DiseaseSexandAgegroups2017.csv          :Classes 'tbl_df', 'tbl' and 'data.frame':    117 obs. of  22 variables:
#>  $ MeansbyDiseaseSex2007_2016.csv          :Classes 'tbl_df', 'tbl' and 'data.frame':    120 obs. of  13 variables:
#>  $ RatesbyDisease2007_2017.csv             :Classes 'tbl_df', 'tbl' and 'data.frame':    62 obs. of  23 variables:
#>  $ RatesbyDiseaseandSex2007_2017.csv       :Classes 'tbl_df', 'tbl' and 'data.frame':    121 obs. of  35 variables:
#>  $ read me file for annual report data.xlsx:Classes 'tbl_df', 'tbl' and 'data.frame':    28 obs. of  3 variables:

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

summary_diseases[["RatesbyDisease2007_2017.csv"]]
#> # A tibble: 62 x 23
#>    Disease X2007 X2007.1 X2008 X2008.1 X2009 X2009.1 X2010 X2010.1 X2011
#>    <chr>   <chr> <chr>   <chr> <chr>   <chr> <chr>   <chr> <chr>   <chr>
#>  1 ""      #     Rate*   #     Rate    #     Rate    #     Rate    #    
#>  2 Acute … 0     0       0     0       0     0       0     0       0    
#>  3 AIDS    98    3.7     111   4.2     68    2.6     61    2.3     67   
#>  4 HIV     619   23.6    541   20.6    532   20      496   18.5    543  
#>  5 "Amebi… 405   15.5    411   15.6    432   16.3    427   16      413  
#>  6 "Botul… 0     0       2     <0.1    1     <0.1    0     0       0    
#>  7 "Bruce… 1     <0.1    1     <0.1    1     <0.1    0     0       0    
#>  8 Campyl… 982   37.5    992   37.7    772   29.1    752   28.1    832  
#>  9 Chicke… 2,931 112     2,327 88.4    2,109 79.5    1,942 72.6    1,633
#> 10 Chlamy… 7,027 268.5   7,379 280.3   7,957 299.8   8,837 330.2   9,844
#> # … with 52 more rows, and 13 more variables: X2011.1 <chr>, X2012 <chr>,
#> #   X2012.1 <chr>, X2013 <chr>, X2013.1 <chr>, X2014 <chr>, X2014.1 <chr>,
#> #   X2015 <chr>, X2015.1 <chr>, X2016 <chr>, X2016.1 <chr>, X2017 <chr>,
#> #   X2017.1 <chr>