From 310663ac749907413e6b5f318fb6992321088deb Mon Sep 17 00:00:00 2001 From: Kevin Cazelles Date: Wed, 22 Apr 2020 20:28:37 -0400 Subject: [PATCH 1/3] :art: make it pass almost seamlessly --- .DS_Store | Bin 6148 -> 0 bytes .Rbuildignore | 3 +++ .gitignore | 2 ++ DESCRIPTION | 9 +++---- R/ckan_package_stack-class.R | 3 ++- R/ckan_resource_stack-class.R | 1 + R/govcan_dl_resources.R | 43 ++++++++++++++++++--------------- R/govcan_get_record.R | 2 +- R/govcan_get_resources.R | 6 ++--- R/govcan_search.R | 6 ++--- R/govcan_setup.R | 6 +++-- README.Rmd | 20 ++++++++------- README.md | 2 +- man/govcan_dl_resources.Rd | 23 +++++++++++++++--- man/govcan_get_record.Rd | 10 +++++--- man/govcan_get_resources.Rd | 4 +-- man/govcan_search.Rd | 11 ++++++--- man/govcan_setup.Rd | 7 ++++-- man/new_ckan_resource_stack.Rd | 2 ++ 19 files changed, 101 insertions(+), 59 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 70dde1a650a8ff9f37bbb9881cd79a1a3066c212..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!Ab)$5KY>uX+`Wou*Y1y_0X!-ld#l!@FuM2L8aYgi(OcEOLuG0b!C4;|Hv=! zcbrMmVyS{B5jz8uH<`>NY)#7>-K9Jig( z752`YWZ)Y6Jc@#u?YI|yf6}dP9Yyxu-90>}PucT}W|hMasASXN6kfrYZSdY6 zg+UbFf^Ql>jUyxmhyh|?i5M_Ppjcm`J=0c+0b<~14B+`7K@ly3xkhz#K!evu94{fF zfQ@enL}}16m}`U)5Ux`Jbt*Sc46f6`FHM|fFxRNl8CNUAJZ5EXUMO6x4t}Y^8Mic2 zOAHVL^9&Sqw~F=u3K*&s gLoAl!8mJQROEds2gSkfVfY3!i(LfC`@T&}b0NQU*ivR!s diff --git a/.Rbuildignore b/.Rbuildignore index 91114bf..dda6de2 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,5 @@ ^.*\.Rproj$ ^\.Rproj\.user$ +README.Rmd +^\.travis.yml +^tmp \ No newline at end of file diff --git a/.gitignore b/.gitignore index 27b862b..005296d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ .Ruserdata data data/* +.DS_Store +tmp/ \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 47e7b21..be1cf9e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,13 +4,12 @@ Title: A package to search for and download data from the Canadian Open Governme Version: 0.1.0 Author: Valentin Lucet [aut, cre] Maintainer: Valentin Lucet -Description: ropencan allows users to serach for existing dataset on the Governement of Canada - open data portal. +Description: rgovcan allows users to search for existing dataset on the Canadian Open Government portal (). Imports: - ckanr, dplyr, tidyr, purrr, data.table + ckanr, dplyr, tidyr, purrr, stringr License: GPL-3 + file LICENSE Encoding: UTF-8 LazyData: true -RoxygenNote: 6.1.1 -Authors@R: person("Valentin", "Lucet", email = "valentin.lucet@mail.mcgill.ca", +RoxygenNote: 7.1.0 +Authors@R: person("Valentin", "Lucet", email = "valentin.lucet@mail.mcgill.ca", role = c("aut", "cre")) diff --git a/R/ckan_package_stack-class.R b/R/ckan_package_stack-class.R index db82e5f..8f83b24 100644 --- a/R/ckan_package_stack-class.R +++ b/R/ckan_package_stack-class.R @@ -6,7 +6,8 @@ new_ckan_package_stack <- function(x = list()){ structure(x, class = "ckan_package_stack", - dim = length(x))} + dim = length(x)) +} #' @export print.ckan_package_stack <- function(x, ...) { diff --git a/R/ckan_resource_stack-class.R b/R/ckan_resource_stack-class.R index df1b2d4..647d6c1 100644 --- a/R/ckan_resource_stack-class.R +++ b/R/ckan_resource_stack-class.R @@ -1,6 +1,7 @@ #' ckan_resource_stack class and helpers #' #' @param x a list +#' @param ... ignored. #' @keywords internal new_ckan_resource_stack <- function(x = list()){ diff --git a/R/govcan_dl_resources.R b/R/govcan_dl_resources.R index 6835d4b..9fb4232 100644 --- a/R/govcan_dl_resources.R +++ b/R/govcan_dl_resources.R @@ -1,9 +1,9 @@ #' 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 #' +#' @description Download resources attached to a specific record or (i.e. a CKAN +#' package) or to a stack of packages. +#' #' @param resources An object of the class ckan_package_stack or ckan_package, or an id of #' a specific record or (i.e. a CKAN package), or an object of type ckan_resource or #' ckan_resource_stack @@ -16,34 +16,36 @@ #' } #' @param where (string) One of "session" is files have to be charged in the session #' or a path to the folder in which to download the files +#' @param ... extra argument(s) #' #' @export -govcan_dl_resources <- function(resources, +govcan_dl_resources <- function(resources, file_formats, where, ...) { UseMethod("govcan_dl_resources") } +#' @describeIn govcan_dl_resources Method for ckan_resource objects. #' @export -govcan_dl_resources.ckan_resource <- function(resource, +govcan_dl_resources.ckan_resource <- function(resources, file_formats = c("CSV"), - where = getwd()){ - all_formats <- unlist(resource$format) + where = getwd(), ...){ + all_formats <- unlist(resources$format) wanted_indices <- (all_formats %in% file_formats) if (wanted_indices == TRUE){ if (where == "session"){ message("Warning: the session option is currently not working well due to issues in ckanr") - ckanr::fetch(resource$url, store = "session") - write_import_messgae(resource) + ckanr::ckan_fetch(resources$url, store = "session") + write_import_message(resources) } else if (where != "session"){ - resource_name <- get_resource_name(resource) + resource_name <- get_resource_name(resources) path <- create_storing_path(where, resource_name) - ckanr::fetch(resource$url, store = "disk", path = path) - write_dl_messgae(resource, path) + ckanr::ckan_fetch(resources$url, store = "disk", path = path) + write_dl_message(resources, path) } } else { @@ -51,15 +53,16 @@ govcan_dl_resources.ckan_resource <- function(resource, } } +#' @describeIn govcan_dl_resources Method for ckan_resource_stack objects. #' @export govcan_dl_resources.ckan_resource_stack <- function(resources, file_formats = c("CSV"), - where = getwd()){ + where = getwd(), ...){ all_formats <- unlist(purrr::map(resources, ~.x$format)) wanted_indices <- which(all_formats %in% file_formats) - if (length(wanted_indices) > 0 ){ + if (length(wanted_indices) > 0){ if (where == "session"){ message("Warning: the session option is currently not working well due to issues in ckanr") @@ -67,8 +70,8 @@ govcan_dl_resources.ckan_resource_stack <- function(resources, for (resource in wanted_indices){ resource_tmp <- resources[[resource]] - ckanr::fetch(resource_tmp$url, store = "session") - write_import_messgae(resource_tmp) + ckanr::ckan_fetch(resource_tmp$url, store = "session") + write_import_message(resource_tmp) } } else if (where != "session"){ @@ -80,8 +83,8 @@ govcan_dl_resources.ckan_resource_stack <- function(resources, resource_name <- get_resource_name(resource_tmp) path <- create_storing_path(where, resource_name) - ckanr::fetch(resource_tmp$url, store = "disk", path = path) - write_dl_messgae(resource_tmp, path) + ckanr::ckan_fetch(resource_tmp$url, store = "disk", path = path) + write_dl_message(resource_tmp, path) } } @@ -112,11 +115,11 @@ create_storing_path <- function(where, resource_name){ path } -write_import_messgae <- function(resource_tmp){ +write_import_message <- function(resource_tmp){ cat("Dataset ", resource_tmp$name, " imported successfully to session") } -write_dl_messgae <- function(resource_tmp, path){ +write_dl_message <- function(resource_tmp, path){ cat(" ---------------------------------------------------------------- \n") cat("",resource_tmp$format, "file named", resource_tmp$name, "downloaded successfully \n") cat(" path to file is:", path, "\n") diff --git a/R/govcan_get_record.R b/R/govcan_get_record.R index 0fa8b25..6618bbb 100644 --- a/R/govcan_get_record.R +++ b/R/govcan_get_record.R @@ -14,7 +14,7 @@ #' @param ... More arguments to be passed on to ckanr::package_show() #' #' @return If only_resources is TRUE, will return only the list of data files (resources) -#' associated with the record querried else it will return all the output of the CKAN query. +#' 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. #' #' @export diff --git a/R/govcan_get_resources.R b/R/govcan_get_resources.R index 66b1297..f76e707 100644 --- a/R/govcan_get_resources.R +++ b/R/govcan_get_resources.R @@ -4,8 +4,8 @@ #' @description Display resources attached to a specific record or (i.e. a CKAN package) #' or to a stack of packages #' -#' @param 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) +#' @param 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). #' #' @return A object of class ckan_resource_stack or list of ckan_resource_stack objetcs #' @@ -30,6 +30,6 @@ govcan_get_resources.ckan_package <- function(x){ govcan_get_resources.character <- function(x){ resource_list <- govcan_get_record(record_id = x, only_resources = TRUE, format_resources = FALSE) - resource_stack <- map(resource_list, ckanr::as.ckan_resource) + resource_stack <- purrr::map(resource_list, ckanr::as.ckan_resource) new_ckan_resource_stack(resource_stack) } diff --git a/R/govcan_search.R b/R/govcan_search.R index 13f76cb..a57b255 100644 --- a/R/govcan_search.R +++ b/R/govcan_search.R @@ -9,7 +9,7 @@ #' @param only_results (logical) Whether the function should return only the results #' without the query metadata (default is TRUE) #' @param format_results (logical) Whether the function should return a formatted output -#' of the results as a tibble or an unformatted version under the form of a list of +#' of the results as a tibble or an unformatted version under the form of a list of #' CKAN packages (default is FALSE) #' @param ... More arguments to be passed on to ckanr::package_search() #' @@ -30,8 +30,8 @@ govcan_search <- function(keywords, paste(keywords, collapse = ", ")) # Collate all keywords - keywords_collated <- paste0(keywords,"+", collapse = "") - keywords_collated <- substr(keywords_collated,1, nchar(keywords_collated)-1) + keywords_collated <- paste0(keywords, "+", collapse = "") + keywords_collated <- substr(keywords_collated, 1, nchar(keywords_collated)-1) # Perform query if (format_results == TRUE) { diff --git a/R/govcan_setup.R b/R/govcan_setup.R index 5e332ee..9c10ec0 100644 --- a/R/govcan_setup.R +++ b/R/govcan_setup.R @@ -1,8 +1,10 @@ -#' Set or reset the ckanr URL to the Open Canada portal URl "https://open.canada.ca/data/en" +#' Set or reset the ckanr URL to the Open Canada portal URL "https://open.canada.ca/data/en" #' -#' @description Set or reset the ckanr URL to the Open Canada portal URl +#' @description Set or reset the ckanr URL to the Open Canada portal URL #' "https://open.canada.ca/data/en" #' +#' @param url Open Canada portal URL. +#' #' @export govcan_setup <- function(url = "https://open.canada.ca/data/en"){ message(paste0("ckanr url set to ", url)) diff --git a/README.Rmd b/README.Rmd index 96b3bd6..33ef78f 100644 --- a/README.Rmd +++ b/README.Rmd @@ -12,18 +12,18 @@ knitr::opts_chunk$set(echo = TRUE) [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) [![Travis-CI Build Status](https://travis-ci.org/VLucet/rgovcan.svg?branch=master)](https://travis-ci.org/vlucet/rgovcan) -A R package to interact with the Open Canada API, to search and download datasets. 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). +A R package to interact with the Open Canada API, to search and download datasets. 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. +This package makes extensive use of `ckanr` to access the Canadian government's CKAN REST API. -The code is under GPL-3 license. +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 -Untill release to CRAN, you will need to use `devtools` to install from source. +Until release to CRAN, you will need to use `devtools` to install from source. ```r devtools::install_github("vlucet/rgovcan") @@ -31,7 +31,7 @@ devtools::install_github("vlucet/rgovcan") ## Usage -1. First, load the package. The default `ckanr` url will be set to the Open Canada Portal. +1. First, load the package. The default `ckanr` url will be set to the Open Canada Portal. ```{r} library("rgovcan") ``` @@ -40,7 +40,7 @@ If you happen to change the default url, you can reset it back to the default wi govcan_setup() ``` -2. A typical workflow with `rgovcan` can start with running `govcan_search` on a given set of keywords. This yiels a `stack` of `ckan_packages` (object of class `ckan_package_stack`). +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} ?govcan_search dfo_search <- govcan_search(keywords = c("dfo"), records = 10) @@ -49,7 +49,7 @@ dfo_search # outputs a `ckan_package_stack` 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 <- "7ac5fe02-308d-4fff-b805-80194f8ddeb4" # Package ID id_search <- govcan_get_record(record_id = id) id_search # outputs a `ckan_package` ``` @@ -65,10 +65,12 @@ 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::fetch`). +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} ?govcan_dl_resources -path <- paste0(getwd(),"/data/") +path <- "tmp/data/" +dir.create(path, recursive = TRUE) govcan_dl_resources(id_resources, file_formats = c("JSON", "CSV", "SHP"), where = path) # govcan_dl_resources(res_pel, file_formats = c("JSON", "CSV", "SHP"), where = "session") ``` diff --git a/README.md b/README.md index 8db57fd..aea5784 100644 --- a/README.md +++ b/README.md @@ -357,7 +357,7 @@ 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::fetch`). + `ckanr::ckan_fetch`). diff --git a/man/govcan_dl_resources.Rd b/man/govcan_dl_resources.Rd index 18b63bd..f237217 100644 --- a/man/govcan_dl_resources.Rd +++ b/man/govcan_dl_resources.Rd @@ -2,10 +2,16 @@ % Please edit documentation in R/govcan_dl_resources.R \name{govcan_dl_resources} \alias{govcan_dl_resources} +\alias{govcan_dl_resources.ckan_resource} +\alias{govcan_dl_resources.ckan_resource_stack} \title{Download the resources attached to a specific record or (i.e. a CKAN package) -or to a stack of packages,} +or to a stack of packages} \usage{ -govcan_dl_resources(resources, ...) +govcan_dl_resources(resources, file_formats, where, ...) + +\method{govcan_dl_resources}{ckan_resource}(resources, file_formats = c("CSV"), where = getwd(), ...) + +\method{govcan_dl_resources}{ckan_resource_stack}(resources, file_formats = c("CSV"), where = getwd(), ...) } \arguments{ \item{resources}{An object of the class ckan_package_stack or ckan_package, or an id of @@ -22,8 +28,17 @@ donwloaded, any of : \item{where}{(string) One of "session" is files have to be charged in the session or a path to the folder in which to download the files} + +\item{...}{extra argument(s)} } \description{ -Download resources attached to a specific record or (i.e. a CKAN package) -or to a stack of packages +Download resources attached to a specific record or (i.e. a CKAN +package) or to a stack of packages. } +\section{Methods (by class)}{ +\itemize{ +\item \code{ckan_resource}: Method for ckan_resource objects. + +\item \code{ckan_resource_stack}: Method for ckan_resource_stack objects. +}} + diff --git a/man/govcan_get_record.Rd b/man/govcan_get_record.Rd index c8ce583..c249682 100644 --- a/man/govcan_get_record.Rd +++ b/man/govcan_get_record.Rd @@ -4,8 +4,12 @@ \alias{govcan_get_record} \title{Query OpenCan portal for a specific record (i.e. a CKAN package)} \usage{ -govcan_get_record(record_id, format_resources = FALSE, - only_resources = FALSE, ... = NULL) +govcan_get_record( + record_id, + format_resources = FALSE, + only_resources = FALSE, + ... = NULL +) } \arguments{ \item{record_id}{(character) The id of the wanted dataset, which can be found with a @@ -23,7 +27,7 @@ with govcan_show_ressources} } \value{ If only_resources is TRUE, will return only the list of data files (resources) -associated with the record querried else it will return all the output of the CKAN query. +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. } \description{ diff --git a/man/govcan_get_resources.Rd b/man/govcan_get_resources.Rd index 031b4b7..234680e 100644 --- a/man/govcan_get_resources.Rd +++ b/man/govcan_get_resources.Rd @@ -8,8 +8,8 @@ or to a stack of packages,} govcan_get_resources(x) } \arguments{ -\item{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)} +\item{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 objetcs diff --git a/man/govcan_search.Rd b/man/govcan_search.Rd index de94bfc..3c455f5 100644 --- a/man/govcan_search.Rd +++ b/man/govcan_search.Rd @@ -4,8 +4,13 @@ \alias{govcan_search} \title{Query OpenCan portal for datasets (CKAN packages) matching keywords} \usage{ -govcan_search(keywords, records = 10, only_results = TRUE, - format_results = FALSE, ... = NULL) +govcan_search( + keywords, + records = 10, + only_results = TRUE, + format_results = FALSE, + ... = NULL +) } \arguments{ \item{keywords}{(character vector) A set of keywords to query} @@ -17,7 +22,7 @@ govcan_search(keywords, records = 10, only_results = TRUE, without the query metadata (default is TRUE)} \item{format_results}{(logical) Whether the function should return a formatted output -of the results as a tibble or an unformatted version under the form of a list of +of the results as a tibble or an unformatted version under the form of a list of CKAN packages (default is FALSE)} \item{...}{More arguments to be passed on to ckanr::package_search()} diff --git a/man/govcan_setup.Rd b/man/govcan_setup.Rd index 5cad41a..831db3e 100644 --- a/man/govcan_setup.Rd +++ b/man/govcan_setup.Rd @@ -2,11 +2,14 @@ % Please edit documentation in R/govcan_setup.R \name{govcan_setup} \alias{govcan_setup} -\title{Set or reset the ckanr URL to the Open Canada portal URl "https://open.canada.ca/data/en"} +\title{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{ +\item{url}{Open Canada portal URL.} +} \description{ -Set or reset the ckanr URL to the Open Canada portal URl +Set or reset the ckanr URL to the Open Canada portal URL "https://open.canada.ca/data/en" } diff --git a/man/new_ckan_resource_stack.Rd b/man/new_ckan_resource_stack.Rd index 7801c68..e63d328 100644 --- a/man/new_ckan_resource_stack.Rd +++ b/man/new_ckan_resource_stack.Rd @@ -8,6 +8,8 @@ new_ckan_resource_stack(x = list()) } \arguments{ \item{x}{a list} + +\item{...}{ignored.} } \description{ ckan_resource_stack class and helpers From 91e571e0f085a607f8711774ae895e84172e5c65 Mon Sep 17 00:00:00 2001 From: Kevin Cazelles Date: Wed, 22 Apr 2020 20:55:21 -0400 Subject: [PATCH 2/3] :art: status ok (0 0 0) --- DESCRIPTION | 2 +- README.Rmd | 9 ++- README.md | 206 +++++++++++++++++++++++++++------------------------- 3 files changed, 115 insertions(+), 102 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index be1cf9e..7808343 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -6,7 +6,7 @@ Author: Valentin Lucet [aut, cre] Maintainer: Valentin Lucet Description: rgovcan allows users to search for existing dataset on the Canadian Open Government portal (). Imports: - ckanr, dplyr, tidyr, purrr, stringr + ckanr, dplyr, purrr, stringr License: GPL-3 + file LICENSE Encoding: UTF-8 LazyData: true diff --git a/README.Rmd b/README.Rmd index 33ef78f..44fd5fb 100644 --- a/README.Rmd +++ b/README.Rmd @@ -1,5 +1,7 @@ --- -output: github_document +output: + md_document: + variant: gfm --- ```{r setup, include=FALSE} @@ -42,10 +44,10 @@ 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} -?govcan_search 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} @@ -68,9 +70,10 @@ 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} -?govcan_dl_resources path <- "tmp/data/" dir.create(path, recursive = TRUE) govcan_dl_resources(id_resources, file_formats = c("JSON", "CSV", "SHP"), where = path) # govcan_dl_resources(res_pel, file_formats = c("JSON", "CSV", "SHP"), where = "session") ``` + +see `?govcan_dl_resources` for further details. \ No newline at end of file diff --git a/README.md b/README.md index aea5784..951e34d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - # rgovcan ## Easy access to the Canadian Open Government Portal @@ -13,7 +12,7 @@ datasets. 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` ). -This package will make extensive use of `ckanr` to access the canadian +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 @@ -24,7 +23,7 @@ Hex Logo done with `hexSticker`: ## Installation -Untill release to CRAN, you will need to use `devtools` to install from +Until release to CRAN, you will need to use `devtools` to install from source. ``` r @@ -56,21 +55,20 @@ govcan_setup() ## ckanr url set to https://open.canada.ca/data/en 2. A typical workflow with `rgovcan` can start with running - `govcan_search` on a given set of keywords. This yiels a `stack` of + `govcan_search` on a given set of keywords. This yields a `stack` of `ckan_packages` (object of class `ckan_package_stack`). ``` r -?govcan_search dfo_search <- govcan_search(keywords = c("dfo"), records = 10) ``` ## Searching the Open Portal for records matching: dfo - ## CKAN query: 202 records found for keywords: dfo + ## CKAN query: 260 records found for keywords: dfo - ## 202 matching records were found, 10 records were returned + ## 260 matching records were found, 10 records were returned ``` r dfo_search # outputs a `ckan_package_stack` @@ -88,8 +86,10 @@ dfo_search # outputs a `ckan_package_stack` ## Title: Results of DFO fish health audits of British Columbian marine finfish aquaculture sites, by facility ## c1a54a0c-4eb0-4b50-be1f-01aee632527e ## Title: Results of DFO benthic audits of British Columbia marine finfish aquaculture sites - ## 29dd835b-7c96-4c62-b558-275dfe13cbe9 - ## Title: Bottlenose Whale Presence, Maritimes Region + ## f32ce23d-4a16-4eaa-9648-2f02a98b91af + ## Title: Oceans Protection Plan Regional Response Planning Extents + +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`. @@ -97,7 +97,7 @@ dfo_search # outputs a `ckan_package_stack` ``` r -id <- "7ac5fe02-308d-4fff-b805-80194f8ddeb4" # Package ID +id <- "7ac5fe02-308d-4fff-b805-80194f8ddeb4" # Package ID id_search <- govcan_get_record(record_id = id) ``` @@ -111,8 +111,8 @@ id_search # outputs a `ckan_package` ## 7ac5fe02-308d-4fff-b805-80194f8ddeb4 ## Title: Pacific Region Commercial Salmon Fishery In-season Catch Estimates - ## Creator/Modified: 2018-09-21T12:18:04.128562 / 2019-02-25T14:40:37.117485 - ## Resources (up to 5): Data Dictionary, Commercial Salmon In-Season Catch Estimates (In Pieces) From 2004 To 2017, Pacific Fishery Management Areas - Feature Layer - Default, Commercial Salmon In-Season Catch Estimates, Commercial Salmon In-Season Catch Estimates + ## Creator/Modified: 2018-09-21T12:18:04.128562 / 2020-04-21T20:33:30.110523 + ## Resources (up to 5): Data Dictionary, Commercial Salmon In-Season Catch Estimates (In Pieces) From 2004 To 2019, Data Dictionary, Commercial Salmon In-Season Catch Estimates (In Pieces) From 2004 To 2019, Pacific Region Commercial Salmon Fishery In-season Catch Estimates ## Tags (up to 5): ## Groups (up to 5): @@ -129,43 +129,25 @@ id_resources <- govcan_get_resources(id_search) id_resources # outputs a `resource_stack` ``` - ## + ## ## ## Resources: ## - ## 9471e6e9-0f1d-40d4-b126-8656472690b1 + ## 593847c4-053d-420c-8429-650ced30e136 ## Name: Data Dictionary ## Format: HTML - ## b402379e-e1d2-4f96-950b-02750dbbcaee - ## Name: Commercial Salmon In-Season Catch Estimates (In Pieces) From 2004 To 2017 + ## 443c62bb-2a85-44fe-bea7-ebf49e65e3da + ## Name: Commercial Salmon In-Season Catch Estimates (In Pieces) From 2004 To 2019 ## Format: CSV - ## 969ae32a-be77-44aa-be46-d09dbdfa893a - ## Name: Pacific Fishery Management Areas - Feature Layer - Default - ## Format: ESRI REST - ## 4aea1ea1-6f61-4e89-bff4-8e87d1101c82 - ## Name: Commercial Salmon In-Season Catch Estimates - ## Format: ESRI REST - ## 22c505bf-7c8a-4950-9071-e3993b299ce1 - ## Name: Commercial Salmon In-Season Catch Estimates - ## Format: ESRI REST - ## 50232624-ab23-4acf-b56a-fea83da4d3ae - ## Name: Pacific Fishery Management Areas - Feature Layer - Default - ## Format: ESRI REST - ## 2978a458-f47c-4e53-92da-dc109943f56c - ## Name: Pacific Fishery Management Areas - Dynamic Layer - PFMA Labels - ## Format: ESRI REST - ## 8bf8f43c-985f-4907-a251-0fa863599d64 - ## Name: Pacific Fishery Management Areas - Dynamic Layer - PFMA Labels - ## Format: ESRI REST - ## be7b32cb-ed75-4d18-93f4-4ea94cfe26ac - ## Name: How to build a multilayered map - ## Format: HTML - ## 1f92c842-9e66-49d9-a040-69e25f9a4be9 - ## Name: How to build a multilayered map - ## Format: HTML - ## e40fe2fd-4fea-4c7e-8194-a65697a9c868 + ## 0186ca95-35fe-4f20-9751-3b92105bf550 ## Name: Data Dictionary ## Format: CSV + ## d94bc8f4-6cce-432f-a229-cd1cb749854d + ## Name: Commercial Salmon In-Season Catch Estimates (In Pieces) From 2004 To 2019 + ## Format: ESRI REST + ## a2f471ac-ee48-4da1-96c4-49973f9cfe67 + ## Name: Pacific Region Commercial Salmon Fishery In-season Catch Estimates + ## Format: ESRI REST Or a list of stacks if called onto a `ckan_package_stack`. @@ -204,10 +186,10 @@ dfo_resources # outputs a list of `resource_stack`s ## Resources: ## ## 26c2c849-b033-4092-8993-e1f50514d096 - ## Name: DFO’s fish health monitoring activities at BC aquaculture sites, 2011- 2018 + ## Name: DFO’s fish health monitoring activities at BC aquaculture sites, 2011 and ongoing ## Format: CSV ## ed82597d-a30c-4f55-a4e2-71d7ac8b7fff - ## Name: DFO’s fish health monitoring activities at BC aquaculture sites, 2011-2018 + ## Name: DFO’s fish health monitoring activities at BC aquaculture sites, 2011 and ongoing ## Format: CSV ## 2bd87c89-a755-4885-b6c5-d14beddc952b ## Name: DFO’s fish health monitoring activities at BC aquaculture sites @@ -246,16 +228,16 @@ dfo_resources # outputs a list of `resource_stack`s ## Resources: ## ## f51236a0-4ccc-4fd1-9fd0-f4a109065732 - ## Name: Results of DFO benthic monitoring audits of BC marine finfish aquaculture sites, 2011 to 2017 + ## Name: Results of DFO benthic monitoring audits of BC marine finfish aquaculture sites, 2011 and ongoing ## Format: CSV ## 220ce25f-534d-46ca-955f-41c8e8046be9 - ## Name: Results of DFO benthic monitoring audits of BC marine finfish aquaculture sites, 2011 to 2017 + ## Name: Results of DFO benthic monitoring audits of BC marine finfish aquaculture sites, 2011 and ongoing ## Format: CSV ## 010b3ad4-21b0-49b5-9269-0946f832818c - ## Name: Results of DFO benthic monitoring audits of BC marine finfish aquaculture sites, 2011 to 2017 + ## Name: Results of DFO benthic monitoring audits of BC marine finfish aquaculture sites, 2011 and ongoing ## Format: CSV ## 57de280e-2516-4309-bac4-170d73f893a5 - ## Name: Results of DFO benthic monitoring audits of BC marine finfish aquaculture sites, 2011 to 2017 + ## Name: Results of DFO benthic monitoring audits of BC marine finfish aquaculture sites, 2011 and ongoing ## Format: CSV ## 8d4eeaee-ead7-432f-a109-10873f8f208d ## Name: Create a Google Map using latitude and longitude data @@ -269,14 +251,14 @@ dfo_resources # outputs a list of `resource_stack`s ## ## Resources: ## - ## d3138042-61c8-4c6f-9ae4-c090245eb428 - ## Name: Ocean Protection Plan Data Dictionary En/Fr - ## Format: CSV - ## 1d435f19-6e8a-4afd-8a1d-e05394cc43af - ## Name: Biota002_MarineMammals_NorthernBottlenoseWhale_PH_SJ_Presence + ## bb01c294-9f21-44ed-bd73-341f18d25419 + ## Name: Oceans Protection Plan Extent- Data Dictionary + ## Format: HTML + ## 28555692-fb08-40d4-865e-83dbe4bfd2e6 + ## Name: Oceans Protection Plan Regional Response Planning Extents ## Format: ESRI REST - ## 3d62646b-bd0e-4327-b894-2882307c2a79 - ## Name: Biota002_MarineMammals_NorthernBottlenoseWhale_PH_SJ_Presence + ## 26a19e90-f21a-44b5-9f49-405d9b751a33 + ## Name: Oceans Protection Plan Regional Response Planning Extents ## Format: ESRI REST ## ## [[6]] @@ -284,75 +266,96 @@ dfo_resources # outputs a list of `resource_stack`s ## ## Resources: ## - ## c4ef0f94-5017-4a8a-9c6e-634d660c5dbc - ## Name: Oceans Protection Plan Data Dictionary En FR - ## Format: CSV - ## 23083bf9-f13d-494b-beaf-5d31cacfb0b5 - ## Name: Biota002_MarineMammals_FinbackWhale_PH_SJ_Presence_En + ## baa41cff-9357-4d41-86f1-26cf4d330040 + ## Name: Federal Marine Bioregions + ## Format: FGDB/GDB + ## 68fdd715-7376-4ff5-a2a2-c758bb1936e1 + ## Name: Federal Marine Bioregions ## Format: ESRI REST - ## 9e1ee5ba-e116-4fc6-be76-7f2e512d0bcb - ## Name: Biota002_MarineMammals_FinbackWhale_PH_SJ_Presence_Fr + ## 00f0c169-ed9f-4b3e-a20b-03fe465f3814 + ## Name: Federal Marine Bioregions ## Format: ESRI REST ## ## [[7]] - ## + ## ## ## Resources: ## - ## 049a6c69-d798-44d9-ba45-c14a9ee26262 - ## Name: Oceans Protection Plan data dictionary EnFr - ## Format: CSV - ## 6692fb52-6ba8-4ee6-a852-f28cdadc050a - ## Name: Biota002_MarineMammals_NorthAtlanticRightWhale_PH_SJ_Presence + ## a5d3af15-dade-4aa6-a4c5-7396c1ac5915 + ## Name: Science Advisory Report 2016/039 + ## Format: HTML + ## 3d2e4fee-4bfb-4ffe-970d-68e70a214fbb + ## Name: Terms of Reference + ## Format: HTML + ## cbee4a17-8af0-4ab7-9ade-1676c0281b0e + ## Name: Proceedings 2017/043 + ## Format: HTML + ## 71c936bd-2519-4b3c-baf9-77ff0a4a60fa + ## Name: Acoustic Doppler Current Profiler data from the Coast of Bays, Newfoundland ## Format: ESRI REST - ## 80d31c7d-1c5b-4c9b-a7c2-d7fbfc77c00e - ## Name: Biota002_MarineMammals_NorthAtlanticRightWhale_PH_SJ_Presence_Fr + ## fcca9fe8-eccd-4e4b-81a9-6f81538bfe7c + ## Name: Acoustic Doppler Current Profiler data from the Coast of Bays, Newfoundland ## Format: ESRI REST + ## 9b7c9269-aa21-4d3d-9979-d3a840c24f60 + ## Name: ADCP Data + ## Format: ZIP + ## 7116b8ba-d6d8-4c7c-90f4-60389c7f9ad2 + ## Name: Coast of Bays ADCP stations 2009-2014 + ## Format: CSV ## ## [[8]] - ## + ## ## ## Resources: ## - ## 82da2921-9531-40d4-b2ea-0dd5f28e5bd9 - ## Name: Oceans Protection Plan Data Dictionary EnFr - ## Format: CSV - ## 50452236-ab3a-4578-8cf6-ec6b6e9e896f - ## Name: Biota002_MarineMammals_HarbourPorpoise_PH_SJ_Presence + ## 983a70a0-435a-4ba4-aaaf-6efa0def06ac + ## Name: Mailing address and contact details for primary offices for Fisheries and Oceans Canada (English) ## Format: ESRI REST - ## 2fb77235-5433-45a4-96f2-acd88d6d7d77 - ## Name: Biota002_MarineMammals_HarbourPorpoise_PH_SJ_Presence_Fr + ## c8970b71-7f77-4c24-ab94-f90ec23af81d + ## Name: Mailing address and contact details for primary offices for Fisheries and Oceans Canada (French) ## Format: ESRI REST ## ## [[9]] - ## + ## ## ## Resources: ## - ## 525432eb-f675-47fc-8828-466276f50e76 - ## Name: Oceans Protection Plan Extent- Data Dictionary - ## Format: HTML - ## 906e284a-3960-4dd3-bccc-4cf502dcda0e - ## Name: Layers + ## 299b5db6-a4f8-4905-a16b-4a4b79887f90 + ## Name: Data Dictionary + ## Format: CSV + ## 6a344c5f-9919-4f70-9e1b-0a96767390c5 + ## Name: EBSA + ## Format: FGDB/GDB + ## 639615c4-b76d-41fa-93db-e4db72ca9f58 + ## Name: EBSA ## Format: ESRI REST - ## 419b181b-1ea3-4689-99d9-daa7a82e8723 - ## Name: Layers + ## f8dc3187-668e-4f4e-8ab6-5c260d204cbd + ## Name: EBSA ## Format: ESRI REST ## ## [[10]] - ## + ## ## ## Resources: ## - ## c8d5a927-0c80-46f8-ac70-c5806de61c31 - ## Name: Federal Marine Bioregions + ## 519d6e21-c5dd-430e-a1f9-4784e4eb8188 + ## Name: Data Dictionary + ## Format: CSV + ## 880b0ddc-1956-4e83-b96e-0042e6324921 + ## Name: NEEC Atlantic Cod Presence MAR ARP Pilots + ## Format: FGDB/GDB + ## 37070e15-4aeb-421a-9680-381defb03303 + ## Name: Atlantic Cod Presence MAR ARP Pilots + ## Format: FGDB/GDB + ## c3349b4f-3de2-429f-afdc-274cb2ff5554 + ## Name: NEEC Data Dictionary + ## Format: CSV + ## 2eb87ea9-4c12-46ab-8f8d-65462df9dc50 + ## Name: Atlantic Cod Presence MAR ARP Pilots ## Format: ESRI REST - ## 89a7de4a-76cf-4797-adef-200485da9ae5 - ## Name: Federal Marine Bioregions + ## 5cf54524-80a6-48fd-aeb6-3822ad38fd7c + ## Name: Atlantic Cod Presence MAR ARP Pilots ## Format: ESRI REST - ## f2a9372e-8bdf-48da-999d-8bd29d2bef10 - ## Name: Federal Marine Bioregions - ## Format: FGDB/GDB 5. Finally, you can download the resources with `govcan_dl_resources`. These can either be stored to a certain directory or load into @@ -362,20 +365,27 @@ dfo_resources # outputs a list of `resource_stack`s ``` r -?govcan_dl_resources -path <- paste0(getwd(),"/data/") +path <- "tmp/data/" +dir.create(path, recursive = TRUE) +``` + + ## Warning in dir.create(path, recursive = TRUE): 'tmp/data' already exists + +``` r govcan_dl_resources(id_resources, file_formats = c("JSON", "CSV", "SHP"), where = path) ``` ## ---------------------------------------------------------------- - ## CSV file named Commercial Salmon In-Season Catch Estimates (In Pieces) From 2004 To 2017 downloaded successfully - ## path to file is: /Users/vlucet/Documents/DocumentsMBP/GitHub/rgovcan/data/CommercialSalmonInSeasonCatchEstimatesInPiecesFrom2004To2017.CSV + ## CSV file named Commercial Salmon In-Season Catch Estimates (In Pieces) From 2004 To 2019 downloaded successfully + ## path to file is: tmp/data/CommercialSalmonInSeasonCatchEstimatesInPiecesFrom2004To2019.CSV ## ---------------------------------------------------------------- ## ---------------------------------------------------------------- ## CSV file named Data Dictionary downloaded successfully - ## path to file is: /Users/vlucet/Documents/DocumentsMBP/GitHub/rgovcan/data/DataDictionary.CSV + ## path to file is: tmp/data/DataDictionary.CSV ## ---------------------------------------------------------------- ``` r # govcan_dl_resources(res_pel, file_formats = c("JSON", "CSV", "SHP"), where = "session") ``` + +see `?govcan_dl_resources` for further details. From 46b1669a1459a7cdc6077213752c1cd429e48be1 Mon Sep 17 00:00:00 2001 From: vlucet Date: Thu, 23 Apr 2020 09:09:04 -0400 Subject: [PATCH 3/3] add ctb to DESCRIPTION --- DESCRIPTION | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index 7808343..3797126 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,3 +13,5 @@ LazyData: true RoxygenNote: 7.1.0 Authors@R: person("Valentin", "Lucet", email = "valentin.lucet@mail.mcgill.ca", role = c("aut", "cre")) + person("Kevin", "Cazelles", email = "kcazelle@uoguelph.ca", + role = c("ctb"))