Package 'rgovcan'

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

Help Index


Download the resources attached to a specific record or (i.e. a CKAN package) or to a stack of packages

Description

Download resources attached to a specific record or (i.e. a CKAN package) or to a stack of packages.

Usage

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, ...)

Arguments

resources

An object of class ckan_package_stack or ckan_package, or a specific resource id, or (i.e. a CKAN package), or an object of type ckan_resource or ckan_resource_stack.

excluded

(vector of characters) Files of this format(s) will not be downloaded (NULL ignores this filter and is the default value).

included

(vector of characters) Only the files of this format(s) will be downloaded (NULL ignores this filter and is the default value).

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 ckanr::ckan_fetch()).

Details

File names are handled internally.

Value

A tibble of the download metadata (file id, package id, url, download path, format, storage location, associated data).

Methods (by class)

  • 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.

Examples

## Not run: 
id <- "b7ca71fa-6265-46e7-a73c-344ded9212b0"
dir <- tempdir(check = TRUE)
res <- govcan_dl_resources(id, path = dir)

## End(Not run)

Query OpenCan portal for a specific record (i.e. a CKAN package)

Description

This function wraps ckanr::package_show() to access a specific record (or package, in CKAN terms) given its unique id

Usage

govcan_get_record(
  record_id,
  format_resources = FALSE,
  only_resources = FALSE,
  ... = NULL
)

Arguments

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 FALSE)

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 ckanr::package_show()

Value

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.

Examples

## Not run: 
pid <- "b7ca71fa-6265-46e7-a73c-344ded9212b0"
pkg <- govcan_get_record(pid)

## End(Not run)

Display or Query resources attached to a specific record or (i.e. a CKAN package) or to a stack of packages

Description

Display resources attached to a specific record or (i.e. a CKAN package) or to a stack of packages

Usage

govcan_get_resources(x)

Arguments

x

An object of the class ckan_package_stack or ckan_package, or an id of a specific record or (i.e. a CKAN package).

Value

A object of class ckan_resource_stack or list of ckan_resource_stack objects.

Examples

## Not run: 
search <- govcan_search("dfo", 10)
id_resources <- govcan_get_resources(search)

## End(Not run)

Set or reset the ckanr URL

Description

Set or reset the ckanr URL to the Open Canada portal URL https://open.canada.ca/data/en

Usage

govcan_setup(url = "https://open.canada.ca/data/en")

Arguments

url

Open Canada portal URL.

Value

This function invisibly returns the URL sent as input.

Examples

## Not run: 
govcan_setup("https://open.canada.ca/data/en")

## End(Not run)