From 1ef7595bf56d24e7e26ed1c0bedace192dd1fb20 Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Thu, 17 Oct 2024 14:44:27 +0200 Subject: [PATCH] Add function `filter_out_timelapse()` Fix #306. --- R/filter_out_timelapse.R | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 R/filter_out_timelapse.R diff --git a/R/filter_out_timelapse.R b/R/filter_out_timelapse.R new file mode 100644 index 00000000..33871753 --- /dev/null +++ b/R/filter_out_timelapse.R @@ -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 + } +}