-
Notifications
You must be signed in to change notification settings - Fork 4
/
README.Rmd
94 lines (66 loc) · 3.7 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
---
output: github_document
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# rgovcan <img src="man/figures/logo.png" align="right" width=140/>
## 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 <https://open.canada.ca/en/access-our-application-programming-interface-api>), to search and download datasets (see Licence at <https://open.canada.ca/en/open-government-licence-canada>). 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.