diff --git a/NAMESPACE b/NAMESPACE index 20abaa6..707099f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,7 @@ export(collect_analyses) export(combine_subspecies) export(filter_bbs_species) export(filter_ts) +export(get_bbs_route_region_data) export(get_cowley_lizards) export(get_cowley_snakes) export(get_default_data_path) diff --git a/R/bbs_cleaning_functions.R b/R/bbs_cleaning_functions.R index 13d7568..8413de9 100644 --- a/R/bbs_cleaning_functions.R +++ b/R/bbs_cleaning_functions.R @@ -6,12 +6,13 @@ #' @param start_yr num first year of time-series #' @param end_yr num last year of time-series #' @param min_num_yrs num minimum number of years of data between start_yr & end_yr +#' @param selected_set optional, a subset of the BBS communities to use (to speed up development). As c(1:X) #' @inheritParams get_mtquad_data #' @return NULL #' @export prepare_bbs_ts_data <- function(start_yr = 1965, end_yr = 2017, min_num_yrs = 10, - path = get_default_data_path()){ + path = get_default_data_path(), selected_set = NULL){ bbs_data_tables <- import_retriever_data("breed-bird-survey", path = path) bbs_data <- bbs_data_tables$breed_bird_survey_weather %>% @@ -48,6 +49,10 @@ prepare_bbs_ts_data <- function(start_yr = 1965, end_yr = 2017, min_num_yrs = 10 } bbs_routes_regions_list = apply(bbs_routes_regions, MARGIN = 1, FUN = make_list) + if(!is.null(selected_set)) { + bbs_routes_regions_list = bbs_routes_regions_list[selected_set] + } + lapply(bbs_routes_regions_list, FUN = subset_bbs_route_region_data, bbs_data_table = bbs_data, species_table = bbs_data_tables$breed_bird_survey_species, path = path) } @@ -105,8 +110,6 @@ subset_bbs_route_region_data <- function(route_region, bbs_data_table, species_t saveRDS(this_bbs_result, file = file.path(storage_path, paste0("route", route, "region", region, ".Rds")) ) - return() - } diff --git a/R/build_plans.R b/R/build_plans.R index 942d927..c10eb99 100644 --- a/R/build_plans.R +++ b/R/build_plans.R @@ -65,6 +65,7 @@ build_analyses_plan <- function(methods, datasets, ...) #' @param data_path where to get the downloaded retriever datasets #' @param include_downloaded_data whether to also include downloadable datasets #' @param include_bbs_data whether to include BBS data +#' @param bbs_subset optional, a subset of the BBS communities to use (to speed up development). As c(1:X) #' #' @return a drake plan (i.e. a tibble) specifying the targets and commands #' for gathering datasets @@ -73,7 +74,8 @@ build_analyses_plan <- function(methods, datasets, ...) #' build_datasets_plan <- function(data_path = get_default_data_path(), include_downloaded_data = FALSE, - include_bbs_data = FALSE) + include_bbs_data = FALSE, + bbs_subset = NULL) { datasets <- drake::drake_plan( maizuru_data = get_maizuru_data(), @@ -97,7 +99,12 @@ build_datasets_plan <- function(data_path = get_default_data_path(), } if (include_bbs_data) { - bbs_datasets = build_bbs_datasets_plan() + bbs_datasets = build_bbs_datasets_plan(data_path = data_path) + + if(!is.null(bbs_subset)) { + bbs_datasets = bbs_datasets[bbs_subset, ] + } + datasets <- datasets %>% dplyr::bind_rows(bbs_datasets) } @@ -107,7 +114,7 @@ build_datasets_plan <- function(data_path = get_default_data_path(), #' @title Generate a Drake Plan for BBS Datasets #' -#' @param data_path path +#' @param path path #' @param from_raw whether to re-prep BBS data #' #' @return a drake plan (i.e. a tibble) specifying the targets and commands @@ -115,19 +122,19 @@ build_datasets_plan <- function(data_path = get_default_data_path(), #' #' @export #' -build_bbs_datasets_plan <- function(path = get_default_data_path()) +build_bbs_datasets_plan <- function(data_path = get_default_data_path()) { - if(!file.exists(file.path(path, "breed-bird-survey-prepped", "routes_and_regions_table.csv"))) { + if(!file.exists(file.path(data_path, "breed-bird-survey-prepped", "routes_and_regions_table.csv"))) { prepare_bbs_ts_data() } - routes_and_regions = read.csv(file.path(path, "breed-bird-survey-prepped", "routes_and_regions_table.csv"), stringsAsFactors = F) + routes_and_regions = read.csv(file.path(data_path, "breed-bird-survey-prepped", "routes_and_regions_table.csv"), stringsAsFactors = F) routes_and_regions = routes_and_regions %>% dplyr::mutate(bcr = as.character(bcr), route = as.character(route)) bbs_datasets <- drake::drake_plan( - bbs_data_rtrg = target(get_bbs_route_region_data(route, region, path = get_default_data_path()), + bbs_data_rtrg = target(get_bbs_route_region_data(route, region, path = !!data_path), transform = map(route = !!rlang::syms(routes_and_regions$route), region = !!rlang::syms(routes_and_regions$bcr) ) diff --git a/man/build_bbs_datasets_plan.Rd b/man/build_bbs_datasets_plan.Rd index 26d4d40..b243ffc 100644 --- a/man/build_bbs_datasets_plan.Rd +++ b/man/build_bbs_datasets_plan.Rd @@ -7,7 +7,7 @@ build_bbs_datasets_plan(path = get_default_data_path()) } \arguments{ -\item{data_path}{path} +\item{path}{path} \item{from_raw}{whether to re-prep BBS data} } diff --git a/man/build_datasets_plan.Rd b/man/build_datasets_plan.Rd index c3581cf..ce7db31 100644 --- a/man/build_datasets_plan.Rd +++ b/man/build_datasets_plan.Rd @@ -5,7 +5,8 @@ \title{Generate a Drake Plan for Datasets} \usage{ build_datasets_plan(data_path = get_default_data_path(), - include_downloaded_data = FALSE, include_bbs_data = FALSE) + include_downloaded_data = FALSE, include_bbs_data = FALSE, + bbs_subset = NULL) } \arguments{ \item{data_path}{where to get the downloaded retriever datasets} @@ -13,6 +14,8 @@ build_datasets_plan(data_path = get_default_data_path(), \item{include_downloaded_data}{whether to also include downloadable datasets} \item{include_bbs_data}{whether to include BBS data} + +\item{bbs_subset}{optional, a subset of the BBS communities to use (to speed up development). As c(1:X)} } \value{ a drake plan (i.e. a tibble) specifying the targets and commands diff --git a/man/filter_ts.Rd b/man/filter_ts.Rd index 4e7c113..0fb3756 100644 --- a/man/filter_ts.Rd +++ b/man/filter_ts.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_retriever_data.R +% Please edit documentation in R/bbs_cleaning_functions.R \name{filter_ts} \alias{filter_ts} \title{Filter BBS to specified time series period and number of samples} diff --git a/man/get_bbs_route_region_data.Rd b/man/get_bbs_route_region_data.Rd new file mode 100644 index 0000000..534bac1 --- /dev/null +++ b/man/get_bbs_route_region_data.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_retriever_data.R +\name{get_bbs_route_region_data} +\alias{get_bbs_route_region_data} +\title{Get cleaned BBS data} +\usage{ +get_bbs_route_region_data(route, region, path = get_default_data_path()) +} +\arguments{ +\item{route}{Route number} + +\item{region}{Region number} + +\item{path}{Data storage path} +} +\value{ +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 `prepare_bbs_data` to create these files from the raw BBS data tables +} diff --git a/man/prepare_bbs_ts_data.Rd b/man/prepare_bbs_ts_data.Rd index 9fe231b..d889085 100644 --- a/man/prepare_bbs_ts_data.Rd +++ b/man/prepare_bbs_ts_data.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_retriever_data.R +% Please edit documentation in R/bbs_cleaning_functions.R \name{prepare_bbs_ts_data} \alias{prepare_bbs_ts_data} \title{Prepare BBS population time-series data} \usage{ prepare_bbs_ts_data(start_yr = 1965, end_yr = 2017, min_num_yrs = 10, - path = get_default_data_path()) + path = get_default_data_path(), selected_set = NULL) } \arguments{ \item{start_yr}{num first year of time-series} @@ -15,6 +15,8 @@ prepare_bbs_ts_data(start_yr = 1965, end_yr = 2017, min_num_yrs = 10, \item{min_num_yrs}{num minimum number of years of data between start_yr & end_yr} \item{path}{where to load the raw data files from} + +\item{selected_set}{optional, a subset of the BBS communities to use (to speed up development). As c(1:X)} } \description{ Modified from https://github.com/weecology/bbs-forecasting diff --git a/man/subset_bbs_route_region_data.Rd b/man/subset_bbs_route_region_data.Rd index 1cd259d..e5d7370 100644 --- a/man/subset_bbs_route_region_data.Rd +++ b/man/subset_bbs_route_region_data.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_retriever_data.R +% Please edit documentation in R/bbs_cleaning_functions.R \name{subset_bbs_route_region_data} \alias{subset_bbs_route_region_data} \title{Subset BBS data by route and reigon