diff --git a/DESCRIPTION b/DESCRIPTION index 9510ddc..e240414 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: portalr Title: Create Useful Summaries of the Portal Data -Version: 0.4.3 +Version: 0.4.4 Authors@R: c(person(given = c("Glenda", "M."), family = "Yenni", diff --git a/NEWS.md b/NEWS.md index f0e8383..ca91760 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,11 +1,19 @@ # portalr + +Version numbers follow [Semantic Versioning](https://semver.org/). + +# portalr 0.4.4 + +* Fix bug in `na_drop = FALSE` that failed to complete missing rows to the treatment level when `time = "newmoon"`. + +# [portalr 0.4.3](https://github.com/weecology/portalr/releases/tag/v0.4.3) +*2024-09-23* + * `load_rodent_data()` now returns an object with an S3 class, and provides a useful message on `print`. * Users can now pass arguments to `download_observations()` from `load_rodent_data()` and other calling functions. * Fix bug in `na_drop = FALSE` that failed to complete missing rows to the species level when `time = "newmoon"`. * Fix bug in `ndvi()` that filtered by sensor only for higher levels. -Version numbers follow [Semantic Versioning](https://semver.org/). - # [portalr 0.4.2](https://github.com/weecology/portalr/releases/tag/v0.4.2) *2024-08-08* diff --git a/R/process_data_utils.R b/R/process_data_utils.R index c913b87..f0ed91a 100644 --- a/R/process_data_utils.R +++ b/R/process_data_utils.R @@ -100,18 +100,20 @@ add_time <- function(summary_table, newmoons_table, time = "period") { { join_summary_newmoon <- dplyr::right_join(newmoons_table, summary_table, by = c("period" = "period")) %>% - dplyr::filter(.data$period <= max(.data$period, na.rm = TRUE)) + dplyr::filter(.data$period <= max(.data$period, na.rm = TRUE)) %>% + tidyr::drop_na(tidyselect::any_of(c("species","plot","treatment"))) } else { newmoons_table$censusdate[is.na(newmoons_table$censusdate)] <- newmoons_table$newmoondate[is.na(newmoons_table$censusdate)] - vars_to_complete <- names(dplyr::select(summary_table,tidyselect::any_of(c("species","plot")))) + vars_to_complete <- + names(dplyr::select(summary_table,tidyselect::any_of(c("species","plot","treatment")))) join_summary_newmoon <- dplyr::left_join(newmoons_table, summary_table, by = "period") %>% tidyr::complete(tidyr::nesting(!!!rlang::syms(c("newmoonnumber", "newmoondate", "censusdate"))), !!!rlang::syms(vars_to_complete)) %>% - tidyr::drop_na(tidyselect::any_of(c("species","plot"))) + tidyr::drop_na(tidyselect::any_of(c("species","plot","treatment"))) } date_vars <- c("newmoondate", "newmoonnumber", "period", "censusdate") vars_to_keep <- switch(tolower(time), diff --git a/R/process_rodent_data.R b/R/process_rodent_data.R index 37287f6..132bcef 100644 --- a/R/process_rodent_data.R +++ b/R/process_rodent_data.R @@ -167,6 +167,10 @@ prep_rodent_output <- function(level_data, effort, na_drop, level_data <- dplyr::select(level_data, -"nplots") } + if (level == "treatment" && "newmoonnumber" %in% names(level_data)) { + level_data <- dplyr::filter(level_data, !(treatment == 'spectabs' & newmoonnumber > 340)) + } + if (output == "rates") { grouping <- switch(level, "plot" = c("species", "plot"), diff --git a/R/summarize_rodents.R b/R/summarize_rodents.R index 796f9fc..d6a1a20 100644 --- a/R/summarize_rodents.R +++ b/R/summarize_rodents.R @@ -87,6 +87,8 @@ summarize_rodent_data <- function(path = get_default_data_path(), time <- tolower(time) output <- tolower(output) + if (! (level %in% c("plot", "treatment", "site"))) {level = "site"} + if (!missing("length")) { warning("The `length` argument is deprecated; please use `plots` instead.") diff --git a/tests/testthat/test-03-summarize-rodents.R b/tests/testthat/test-03-summarize-rodents.R index 9fc1546..c1e8c09 100644 --- a/tests/testthat/test-03-summarize-rodents.R +++ b/tests/testthat/test-03-summarize-rodents.R @@ -131,7 +131,7 @@ test_that("abundance filters at the plot level correctly", { min_plots = 1, min_traps = 1, effort = TRUE, na_drop = FALSE) %>% dplyr::filter(ntraps < 1, period <= 463) - expect_equal(NROW(incomplete_plots), 238) + expect_equal(NROW(incomplete_plots), 213) incomplete_plots <- abundance(path = portal_data_path, level = "plot", min_plots = 1, min_traps = 1, effort = TRUE) %>%