Skip to content

Commit

Permalink
Add function for downloading all the retriever datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
ha0ye committed Jul 11, 2019
1 parent 9fd2796 commit 8c46de6
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
7 changes: 5 additions & 2 deletions R/get_retriever_data.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 31 additions & 4 deletions R/utils-retriever-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -113,4 +112,32 @@ import_retriever_data <- function(dataset, path = get_default_data_path())
stringsAsFactors = FALSE)
}
return(tempdata)
}
}

#' @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)
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion man/get_bbs_route_region_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion man/install_retriever_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8c46de6

Please sign in to comment.