Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sharlagelfand/opendatatoronto
Access data from the City of Toronto Open Data Portal in R.
https://github.com/sharlagelfand/opendatatoronto
Last synced: 3 months ago
JSON representation
Access data from the City of Toronto Open Data Portal in R.
- Host: GitHub
- URL: https://github.com/sharlagelfand/opendatatoronto
- Owner: sharlagelfand
- License: other
- Created: 2019-06-21T17:32:13.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-04-11T20:24:19.000Z (almost 3 years ago)
- Last Synced: 2024-11-17T07:49:50.238Z (3 months ago)
- Language: R
- Homepage: https://sharlagelfand.github.io/opendatatoronto
- Size: 5.12 MB
- Stars: 63
- Watchers: 8
- Forks: 12
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
message = FALSE
)
```
# opendatatoronto[](https://github.com/sharlagelfand/opendatatoronto/actions)
[](https://ci.appveyor.com/project/sharlagelfand/opendatatoronto)
[](https://app.codecov.io/gh/sharlagelfand/opendatatoronto?branch=main)
[](https://cran.r-project.org/package=opendatatoronto)
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://r-pkg.org/pkg/opendatatoronto)`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
```