knitr::opts_chunk$set(echo = TRUE)

rgovcan

Easy Access to the Canadian Open Government Portal

License: GPL v3 R-CMD-check Codecov test coverage CRAN Version Downloads

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:

install.packages("rgovcan")

For the development version, you will need to use remotes to install from source:

install.packages("remotes")
remotes::install_github("vlucet/rgovcan")

Usage

  1. First, load the package. The default ckanr url will be set to the Open Canada Portal.
library("rgovcan")

If you happen to change the default url, you can reset it back to the default with govcan_setup().

govcan_setup()
  1. 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).
dfo_search <- govcan_search(keywords = c("dfo"), records = 10)
dfo_search # outputs a `ckan_package_stack`

see ?govcan_search for further details.

  1. Another possibility is to start with a package id corresponding to an actual record and retrieve a ckan_package.
id <- "7ac5fe02-308d-4fff-b805-80194f8ddeb4" # Package ID
id_search <- govcan_get_record(record_id = id)
id_search # outputs a `ckan_package`
  1. Once the packages have been retrieved from the portal, you can use govcan_get_resources on those results to display the ckan_resources 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.
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.

dfo_resources <- govcan_get_resources(dfo_search)
dfo_resources # outputs a list of `resource_stack`s
  1. 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).
path <- "tmp/data/"
dir.create(path, recursive = TRUE)
govcan_dl_resources(id_resources, path = path)

see ?govcan_dl_resources for further details.



VLucet/rgovcan documentation built on Nov. 24, 2022, 6:52 p.m.