Title: | Easy Access to the Canadian Open Government Portal |
---|---|
Description: | Allows to search for existing resources, including datasets, on the Canadian Open Government portal (<https://open.canada.ca/en>). It is also designed to allow users to easily download a range of files directly from the portal in a reproducible manner. |
Authors: | Valentin Lucet [aut, cre], Kevin Cazelles [ctb] |
Maintainer: | Valentin Lucet <[email protected]> |
License: | GPL-3 |
Version: | 1.0.4 |
Built: | 2024-11-03 02:49:07 UTC |
Source: | https://github.com/VLucet/rgovcan |
Download resources attached to a specific record or (i.e. a CKAN package) or to a stack of packages.
govcan_dl_resources(resources, excluded, included, path, id_as_filename, ...) ## S3 method for class 'ckan_resource' govcan_dl_resources( resources, excluded = NULL, included = NULL, path = ".", id_as_filename = FALSE, ... ) ## S3 method for class 'ckan_resource_stack' govcan_dl_resources(resources, ...) ## S3 method for class 'character' govcan_dl_resources(resources, ...) ## S3 method for class 'ckan_package' govcan_dl_resources(resources, ...) ## S3 method for class 'ckan_package_stack' govcan_dl_resources(resources, ...)
govcan_dl_resources(resources, excluded, included, path, id_as_filename, ...) ## S3 method for class 'ckan_resource' govcan_dl_resources( resources, excluded = NULL, included = NULL, path = ".", id_as_filename = FALSE, ... ) ## S3 method for class 'ckan_resource_stack' govcan_dl_resources(resources, ...) ## S3 method for class 'character' govcan_dl_resources(resources, ...) ## S3 method for class 'ckan_package' govcan_dl_resources(resources, ...) ## S3 method for class 'ckan_package_stack' govcan_dl_resources(resources, ...)
resources |
An object of class |
excluded |
(vector of characters) Files of this format(s) will not be
downloaded ( |
included |
(vector of characters) Only the files of this format(s) will
be downloaded ( |
path |
(character) name indicating where to store the data (default is the current working directory). |
id_as_filename |
(logical) Use the resource identifier as file name. This is particularly useful when two different resources have the same filename. |
... |
Curl arguments passed on to crul::verb-GET (see |
File names are handled internally.
A tibble of the download metadata (file id, package id, url, download path, format, storage location, associated data).
ckan_resource
: Method for ckan_resource objects.
ckan_resource_stack
: Method for ckan_resource_stack
objects.
character
: Method for character
objects.
ckan_package
: Method for ckan_package
objects.
ckan_package_stack
: Method for ckan_package_stack
objects.
## Not run: id <- "b7ca71fa-6265-46e7-a73c-344ded9212b0" dir <- tempdir(check = TRUE) res <- govcan_dl_resources(id, path = dir) ## End(Not run)
## Not run: id <- "b7ca71fa-6265-46e7-a73c-344ded9212b0" dir <- tempdir(check = TRUE) res <- govcan_dl_resources(id, path = dir) ## End(Not run)
This function wraps ckanr::package_show()
to access a specific record
(or package, in CKAN terms) given its unique id
govcan_get_record( record_id, format_resources = FALSE, only_resources = FALSE, ... = NULL )
govcan_get_record( record_id, format_resources = FALSE, only_resources = FALSE, ... = NULL )
record_id |
(character) The id of the wanted dataset, which can be found with a search using govcan_search, or on https://open.canada.ca/en. The id is of the form "4a2929ce-d6b1-49b0-b520-63be0859c552" |
format_resources |
(logical) Whether the function should return a formatted output
of the resources as a tibble or an unformatted list of resources (default is |
only_resources |
(logical) Whether the function should return only the resources from the record (list of files available for download). Resources can also be accessed with govcan_show_ressources |
... |
More arguments to be passed on to |
If only_resources is TRUE
, will return only the list of data files (resources)
associated with the record queried else it will return all the output of the CKAN query.
If format_resources is TRUE
, the resources are formatted to a tibble.
## Not run: pid <- "b7ca71fa-6265-46e7-a73c-344ded9212b0" pkg <- govcan_get_record(pid) ## End(Not run)
## Not run: pid <- "b7ca71fa-6265-46e7-a73c-344ded9212b0" pkg <- govcan_get_record(pid) ## End(Not run)
Display resources attached to a specific record or (i.e. a CKAN package) or to a stack of packages
govcan_get_resources(x)
govcan_get_resources(x)
x |
An object of the class |
A object of class ckan_resource_stack
or list of ckan_resource_stack objects.
## Not run: search <- govcan_search("dfo", 10) id_resources <- govcan_get_resources(search) ## End(Not run)
## Not run: search <- govcan_search("dfo", 10) id_resources <- govcan_get_resources(search) ## End(Not run)
This function wraps ckanr::package_search()
to search for any
records matching a given set of keywords within the Open Canada Portal.
govcan_search( keywords, records = 10, only_results = TRUE, format_results = FALSE, ... )
govcan_search( keywords, records = 10, only_results = TRUE, format_results = FALSE, ... )
keywords |
(character vector) A set of keywords to query. |
records |
(numeric) The number of matching records to return from the CKAN query (number of rows in the JSON output), default to 10. |
only_results |
(logical) Whether the function should return only the
results without the query metadata (default is |
format_results |
(logical) Whether the function should return a
formatted output of the results as a |
... |
More arguments to be passed on to |
If only_results
is TRUE
and format_results
is FALSE
(recommended), will return only the results of the search as a
CKAN_package_stack
. If only_results
is FALSE
, will return a list
including also the query metadata. If format_results
is TRUE
, the
function formats the output as a data frame (not CKAN packages).
## Not run: search <- govcan_search("dfo", 10) search_format <- govcan_search("dfo", 10, format_results = TRUE) search_list <- govcan_search("dfo", 10, only_results = FALSE) search_list_format <- govcan_search("dfo", 10, format_results = TRUE, only_results = FALSE) ## End(Not run)
## Not run: search <- govcan_search("dfo", 10) search_format <- govcan_search("dfo", 10, format_results = TRUE) search_list <- govcan_search("dfo", 10, only_results = FALSE) search_list_format <- govcan_search("dfo", 10, format_results = TRUE, only_results = FALSE) ## End(Not run)
Set or reset the ckanr URL to the Open Canada portal URL https://open.canada.ca/data/en
govcan_setup(url = "https://open.canada.ca/data/en")
govcan_setup(url = "https://open.canada.ca/data/en")
url |
Open Canada portal URL. |
This function invisibly returns the URL sent as input.
## Not run: govcan_setup("https://open.canada.ca/data/en") ## End(Not run)
## Not run: govcan_setup("https://open.canada.ca/data/en") ## End(Not run)