From 8c46de62f0ce9a4e32f16eebb420d7bb6bffe51d Mon Sep 17 00:00:00 2001 From: Hao Ye Date: Thu, 11 Jul 2019 17:36:50 -0400 Subject: [PATCH] Add function for downloading all the retriever datasets --- R/get_retriever_data.R | 7 +++++-- R/utils-retriever-data.R | 35 ++++++++++++++++++++++++++++---- _pkgdown.yml | 1 + man/get_bbs_route_region_data.Rd | 5 ++++- man/install_retriever_data.Rd | 14 ++++++++++++- 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/R/get_retriever_data.R b/R/get_retriever_data.R index 85b5095..8bbdec8 100644 --- a/R/get_retriever_data.R +++ b/R/get_retriever_data.R @@ -1,5 +1,8 @@ -#' Get cleaned BBS data -#' @description Gets prepped BBS data (as a list of abundance, covariates, and metadata) for a specified route and region. First run `prepare_bbs_data` to create these files from the raw BBS data tables +#' @title Get cleaned BBS data +#' @description Gets prepped BBS data (as a list of abundance, covariates, and +#' metadata) for a specified route and region. First run `prepare_bbs_data` +#' to create these files from the raw BBS data tables. If the files are not +#' found, then `NULL` is returned. #' @param route Route number #' @param region Region number #' @param path Data storage path diff --git a/R/utils-retriever-data.R b/R/utils-retriever-data.R index 7e76302..94c6521 100644 --- a/R/utils-retriever-data.R +++ b/R/utils-retriever-data.R @@ -30,7 +30,7 @@ use_default_data_path <- function(path = NULL) portalr::use_default_data_path(path, ENV_VAR = "MATSS_DATA_PATH") } -#' @title Download a dataset from data retriever +#' @title Download data from the data retriever #' @aliases import_retriever_data #' #' @description \code{install_retriever_data} downloads retriever datasets and @@ -59,7 +59,7 @@ install_retriever_data <- function(dataset, path = get_default_data_path(), folder_path <- file.path(path, dataset) if (dir.exists(folder_path) && !force_install) { - message("A folder already exists for \"", dataset, "\".\n", + message("A folder already exists for \"", dataset, "\"... skipping.\n", "Use `force_install = TRUE` to overwrite it with a fresh install.") } else { # make the folder @@ -75,7 +75,6 @@ install_retriever_data <- function(dataset, path = get_default_data_path(), } } -#' @title Import a dataset downloaded from data retriever #' @rdname install_retriever_data #' #' @description \code{import_retriever_data} loads a previously downloaded @@ -113,4 +112,32 @@ import_retriever_data <- function(dataset, path = get_default_data_path()) stringsAsFactors = FALSE) } return(tempdata) -} \ No newline at end of file +} + +#' @rdname install_retriever_data +#' +#' @description \code{download_datasets} is a wrapper around +#' \code{\link{install_retriever_data}} to download multiple datasets, with +#' the default to download all of the datasets that are supported. +#' +#' @inheritParams install_retriever_data +#' +#' @return NULL +#' +#' @examples +#' \dontrun{ +#' download_datasets() +#' } + +download_datasets <- function(dataset = c("breed-bird-survey", + "veg-plots-sdl", + "mapped-plant-quads-mt", + "biotimesql"), + path = get_default_data_path(), + force_install = FALSE) +{ + purrr::walk(dataset, + install_retriever_data, + path = path, + force_install = force_install) +} diff --git a/_pkgdown.yml b/_pkgdown.yml index 84a11b6..61d8103 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -21,6 +21,7 @@ reference: - title: "Rdataretriever" desc: "Functions that use Rdataretriever to download and import data" contents: + - download_retriever_datasets - import_retriever_data - install_retriever_data - title: "Get Data" diff --git a/man/get_bbs_route_region_data.Rd b/man/get_bbs_route_region_data.Rd index 2c73c28..7038f3d 100644 --- a/man/get_bbs_route_region_data.Rd +++ b/man/get_bbs_route_region_data.Rd @@ -17,5 +17,8 @@ get_bbs_route_region_data(route, region, path = get_default_data_path()) list of abundance, covariates, and metadata } \description{ -Gets prepped BBS data (as a list of abundance, covariates, and metadata) for a specified route and region. First run \code{prepare_bbs_data} to create these files from the raw BBS data tables +Gets prepped BBS data (as a list of abundance, covariates, and +metadata) for a specified route and region. First run \code{prepare_bbs_data} +to create these files from the raw BBS data tables. If the files are not +found, then \code{NULL} is returned. } diff --git a/man/install_retriever_data.Rd b/man/install_retriever_data.Rd index 45b0562..f3bc304 100644 --- a/man/install_retriever_data.Rd +++ b/man/install_retriever_data.Rd @@ -3,12 +3,17 @@ \name{install_retriever_data} \alias{install_retriever_data} \alias{import_retriever_data} -\title{Download a dataset from data retriever} +\alias{download_datasets} +\title{Download data from the data retriever} \usage{ install_retriever_data(dataset, path = get_default_data_path(), force_install = FALSE) import_retriever_data(dataset, path = get_default_data_path()) + +download_datasets(dataset = c("breed-bird-survey", "veg-plots-sdl", + "mapped-plant-quads-mt", "biotimesql"), path = get_default_data_path(), + force_install = FALSE) } \arguments{ \item{dataset}{the name of the dataset that you wish to download} @@ -24,6 +29,10 @@ is a wrapper around rdataretriever::install \code{import_retriever_data} loads a previously downloaded retriever dataset + +\code{download_datasets} is a wrapper around +\code{\link{install_retriever_data}} to download multiple datasets, with +the default to download all of the datasets that are supported. } \examples{ \dontrun{ @@ -32,4 +41,7 @@ retriever dataset \dontrun{ import_retriever_data("veg-plots-sdl") } +\dontrun{ + download_datasets() +} }