Skip to content

Commit

Permalink
Fill out treatment level nas, closes #309
Browse files Browse the repository at this point in the history
  • Loading branch information
gmyenni committed Nov 21, 2024
1 parent 2f6b2bc commit ec734fc
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 10 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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*

Expand Down
8 changes: 5 additions & 3 deletions R/process_data_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions R/process_rodent_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions R/summarize_rodents.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-03-summarize-rodents.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>%
Expand Down

0 comments on commit ec734fc

Please sign in to comment.