knitr::opts_chunk$set(echo = TRUE)
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
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")
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()
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.
ckan_package
.id <- "7ac5fe02-308d-4fff-b805-80194f8ddeb4" # Package ID id_search <- govcan_get_record(record_id = id) id_search # outputs a `ckan_package`
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.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
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.