-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Create `individuals()`
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#' Get individuals | ||
#' | ||
#' Gets the (unique) individuals from the observations of a Camera Trap Data | ||
#' Package object. | ||
#' | ||
#' @inheritParams print.camtrapdp | ||
#' @return A [tibble::tibble()] data frame with the individuals that have an | ||
#' `individualID`, containing the following columns: | ||
#' - `individualID` | ||
#' - `scientificName` | ||
#' - `lifeStage` | ||
#' - `sex` | ||
#' @family accessor functions | ||
#' @export | ||
#' @examples | ||
#' x <- example_dataset() | ||
#' individuals(x) | ||
individuals <- function(x) { | ||
check_camtrapdp(x) | ||
observations(x) %>% | ||
dplyr::filter(!is.na(individualID)) %>% | ||
dplyr::distinct( | ||
.data$individualID, | ||
.data$scientificName, | ||
.data$lifeStage, | ||
.data$sex | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
test_that("individuals() returns a tibble", { | ||
skip_if_offline() | ||
x <- example_dataset() | ||
expect_s3_class(individuals(x), "tbl") | ||
}) | ||
|
||
test_that("individuals() returns the expected columns", { | ||
skip_if_offline() | ||
x <- example_dataset() | ||
expected_cols <- c( | ||
"individualID", | ||
"scientificName", | ||
"lifeStage", | ||
"sex" | ||
) | ||
expect_named(individuals(x), expected_cols) | ||
}) | ||
|
||
test_that("individuals() returns the expected rows (unique individuals)", { | ||
skip_if_offline() | ||
x <- example_dataset() | ||
|
||
# Expect 0 individuals | ||
expect_equal(nrow(individuals(x)), 0) | ||
|
||
# Add 3 individuals to event 79204343 | ||
# TODO: remove once https://github.com/tdwg/camtrap-dp/issues/396 is released | ||
x$data$observations[x$data$observations$observationID == "05230014",]$individualID <- "Fezzik" | ||
x$data$observations[x$data$observations$observationID == "5ead5692",]$individualID <- "Buttercup" | ||
x$data$observations[x$data$observations$observationID == "29939500",]$individualID <- "Westley" | ||
expect_equal(nrow(individuals(x)), 3) | ||
}) |