Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vlucet/rgovcan
Easy access to the Canadian Open Government Portal
https://github.com/vlucet/rgovcan
api-wrapper canada openscience package r
Last synced: 10 days ago
JSON representation
Easy access to the Canadian Open Government Portal
- Host: GitHub
- URL: https://github.com/vlucet/rgovcan
- Owner: VLucet
- Created: 2019-05-11T16:52:15.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-11-24T15:09:32.000Z (almost 2 years ago)
- Last Synced: 2024-10-12T23:41:14.656Z (26 days ago)
- Topics: api-wrapper, canada, openscience, package, r
- Language: R
- Homepage: https://vlucet.github.io/rgovcan/
- Size: 716 KB
- Stars: 22
- Watchers: 4
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
output: github_document
---```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
```# rgovcan
## Easy Access to the Canadian Open Government Portal[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)
[![R-CMD-check](https://github.com/VLucet/rgovcan/workflows/R-CMD-check/badge.svg)](https://github.com/VLucet/rgovcan/actions)
[![Codecov test coverage](https://codecov.io/gh/VLucet/rgovcan/branch/master/graph/badge.svg)](https://codecov.io/gh/VLucet/rgovcan?branch=master)
[![CRAN Version](https://img.shields.io/cran/v/rgovcan?label=CRAN)](https://CRAN.R-project.org/package=rgovcan)
[![Downloads](https://cranlogs.r-pkg.org/badges/rgovcan?color=blue)](https://CRAN.R-project.org/package=rgovcan/)A R package to interact with the Open Canada API (see ), to search and download datasets (see Licence at ). It is our hope that we will be able to bring this package up to the standard of a `ropensci` packages (see this issue on `ropensci/wishlist` https://github.com/ropensci/wishlist/issues/27).
This package makes extensive use of `ckanr` to access the Canadian government's CKAN REST API.
The code is under GPL-3 license. All the data is under Open Government License
(http://open.canada.ca/en/open-government-licence-canada).Hex Logo done with `hexSticker`: https://github.com/GuangchuangYu/hexSticker
## Installation
You can install `rgovcan` from CRAN like so:
```r
install.packages("rgovcan")
```For the development version, you will need to use [`remotes`](https://CRAN.R-project.org/package=remotes) to install from source:
```r
install.packages("remotes")
remotes::install_github("vlucet/rgovcan")
```## Usage
1. First, load the package. The default [`ckanr`](https://CRAN.R-project.org/package=ckanr) url will be set to the Open Canada Portal.
```{r}
library("rgovcan")
```If you happen to change the default url, you can reset it back to the default with `govcan_setup()`.
```{r}
govcan_setup()
```2. A typical workflow with `rgovcan` can start with running `govcan_search()` on a given set of keywords. This yields a `stack` of `ckan_packages()` (object of class `ckan_package_stack`).
```{r}
dfo_search <- govcan_search(keywords = c("dfo"), records = 10)
dfo_search # outputs a `ckan_package_stack`
```see `?govcan_search` for further details.
3. Another possibility is to start with a package id corresponding to an actual record and retrieve a `ckan_package`.
```{r}
id <- "7ac5fe02-308d-4fff-b805-80194f8ddeb4" # Package ID
id_search <- govcan_get_record(record_id = id)
id_search # outputs a `ckan_package`
```4. Once the packages have been retrieved from the portal, you can use `govcan_get_resources` on those results to display the `ckan_resource`s contained in the packages (a "resource" is any dataset attached to a given record). This outputs a `ckan_resource_stack` when called on a unique package.
```{r}
id_resources <- govcan_get_resources(id_search)
id_resources # outputs a `resource_stack`
```Or a list of stacks if called onto a `ckan_package_stack`.
```{r}
dfo_resources <- govcan_get_resources(dfo_search)
dfo_resources # outputs a list of `resource_stack`s
```5. Finally, you can download the resources with `govcan_dl_resources()`. These can either be stored to a certain directory or load into session (* this option might fail due to current issues with `ckanr::ckan_fetch`).
```{r}
path <- "tmp/data/"
dir.create(path, recursive = TRUE)
govcan_dl_resources(id_resources, path = path)
```see `?govcan_dl_resources` for further details.