Skip to content

Commit

Permalink
Add function filter_out_timelapse()
Browse files Browse the repository at this point in the history
Fix #306.
  • Loading branch information
damianooldoni committed Oct 17, 2024
1 parent e217812 commit 1ef7595
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions R/filter_out_timelapse.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#' Filter out timelapse observations
#'
#' Subsets observations in a Camera Trap Data Package object, removing timelapse
#' observations, i.e. observations where `captureMethod` = `timeLapse`. This
#' function is a shortcut for `filter_observations(x, captureMethod !=
#' "timelapse")`.
#'
#' @inheritParams get_species
#'
#' @return `x` filtered.
#' @family filter functions
#' @export
#'
#' @examples
#' x <- example_dataset()
#'
#' # `x` doesn't contain timelapse observations, returned as is
#' filter_out_timelapse(x)
#'
#' # Create a data package with timelapse observations
#' obs <- observations(x)
#' obs$captureMethod <- rep("timelapse", nrow(obs) - 1)
#' observations(x) <- obs
#' # Filter out timelapse observations
#' filter_out_timelapse(x)
filter_out_timelapse <- function(x) {
if ("captureMethod" %in% names(observations(x))) {
x %>%
filter_observations(captureMethod != "timelapse")
} else {
x
}
}

0 comments on commit 1ef7595

Please sign in to comment.