-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathREADME.Rmd
102 lines (73 loc) · 4.32 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
message = FALSE
)
```
# opendatatoronto <img src="man/figures/logo.png" align="right" height="139" />
<!-- badges: start -->
[![R build status](https://github.com/sharlagelfand/opendatatoronto/workflows/R-CMD-check/badge.svg)](https://github.com/sharlagelfand/opendatatoronto/actions)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/sharlagelfand/opendatatoronto?branch=main&svg=true)](https://ci.appveyor.com/project/sharlagelfand/opendatatoronto)
[![Codecov test coverage](https://codecov.io/gh/sharlagelfand/opendatatoronto/branch/main/graph/badge.svg)](https://app.codecov.io/gh/sharlagelfand/opendatatoronto?branch=main)
[![CRAN status](https://www.r-pkg.org/badges/version/opendatatoronto)](https://cran.r-project.org/package=opendatatoronto)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/grand-total/opendatatoronto?color=blue)](https://r-pkg.org/pkg/opendatatoronto)
<!-- badges: end -->
`opendatatoronto` is an R interface to the [City of Toronto Open Data Portal](https://open.toronto.ca/). The goal of the package is to help read data directly into R without needing to manually download it via the portal.
For more information, please visit the [package website](https://sharlagelfand.github.io/opendatatoronto/) and vignettes:
* [Introduction to `opendatatoronto`](https://sharlagelfand.github.io/opendatatoronto/articles/opendatatoronto.html)
* [Retrieving multi-sheet XLS/XLSX resources](https://sharlagelfand.github.io/opendatatoronto/articles/articles/multisheet_resources.html)
* [Retrieving multi-file ZIP resources](https://sharlagelfand.github.io/opendatatoronto/articles/articles/multifile_zip_resources.html)
* [Retrieving multiple resources using `purrr`](https://sharlagelfand.github.io/opendatatoronto/articles/articles/multiple_resources_purrr.html)
* [Working with spatial data from the portal](https://sharlagelfand.github.io/opendatatoronto/articles/articles/spatial_data.html)
## Installation
You can intall the released version of opendatatoronto from CRAN:
```r
install.packages("opendatatoronto")
```
or the development version from GitHub with:
``` r
devtools::install_github("sharlagelfand/opendatatoronto", ref = "main")
```
## Usage
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, any civic issues it addresses, a description of it, how many resources there are (and their formats), how often it is is refreshed and when it was last refreshed.
```{r list-packages-example}
library(opendatatoronto)
packages <- list_packages(limit = 10)
packages
```
You can also search packages by title:
```{r search-packages-example}
ttc_packages <- search_packages("ttc")
ttc_packages
```
Or see metadata for a specific package:
```{r show-packages-example}
show_package("996cfe8d-fb35-40ce-b569-698d51fc683b")
```
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()`. You can pass it the package id (which is contained in `marriage_license_packages` below):
```{r list-marriage-license-resources}
marriage_licence_packages <- search_packages("Marriage Licence Statistics")
marriage_licence_resources <- marriage_licence_packages %>%
list_package_resources()
marriage_licence_resources
```
But you can also get a list of resources by using the package's URL from the Portal:
```{r list-resources-url}
list_package_resources("https://open.toronto.ca/dataset/sexual-health-clinic-locations-hours-and-services/")
```
Finally (and most usefully!), you can download the resource (i.e., the actual data) directly into R using `get_resource()`:
```{r get-marriage-licenses}
marriage_licence_statistics <- marriage_licence_resources %>%
head(1) %>%
get_resource()
marriage_licence_statistics
```