Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: camtraptor
Title: Explore and Visualize Camera Trap Data Packages
Version: 1.0.0.9000
Version: 1.0.1
Date: 2026-09-09
Authors@R: c(
person("Damiano", "Oldoni", , "damiano.oldoni@inbo.be", role = c("aut", "cre"),
Expand All @@ -19,6 +19,7 @@ Authors@R: c(
comment = c(ORCID = "0000-0001-6788-5876", affiliation = "Research Institute for Nature and Forest (INBO)")),
person("Nele", "Mullens", role = "ctb",
comment = c(ORCID = "0000-0002-3054-9665", affiliation = "Regionaal Landschap Dijleland vzw")),
person("northfox", , , "vulpes.engineer@gmail.com", role = "ctb"),
person("Raphaël", "Nussbaumer", , "rafnuss@gmail.com", role = "ctb",
Comment thread
damianooldoni marked this conversation as resolved.
comment = c(ORCID = "0000-0002-8185-1020", affilication = "Swiss Ornithological Institute")),
person("Thierry", "Onkelinx", , "thierry.onkelinx@inbo.be", role = "ctb",
Expand Down
10 changes: 9 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# camtraptor (development version)
# camtraptor 1.0.1

## Bug fixes

- Fixed an issue where `summarize_observations()` counted a scientific name once per deployment when `group_by` did not contain `deploymentID` (#432).

## Other changes

- Add [northfox](https://github.com/northfox) as contributor. Welcome northfox!

# camtraptor 1.0.0

Expand Down
24 changes: 21 additions & 3 deletions R/summarize_observations.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,36 @@ summarize_observations <- function(
formula_n_species <- rlang::expr(
"n_scientificName" := sum(.data$n_scientificName, na.rm = TRUE)
)
# Calculate n_scientificName
# Calculate n_scientificName. The number of distinct scientific names is not
# additive across deployments: a scientific name observed in more than one
# deployment would be counted more than once. So, retain the scientific names
# by grouping by `scientificName` as well and count the distinct scientific
# names over all deployments afterwards.
n_species_df <- calc_obs_feature(
deployment_ids = deployment_ids,
deployments = deployments,
observations = observations,
group_by_deployments = group_by_deployments,
group_by_observations = group_by_observations,
group_by_observations = union(group_by_observations, "scientificName"),
group_time_by = group_time_by,
col_obs_for_feature = "scientificName",
formula_per_deployment = formula_n_species_per_dep,
formula_total = formula_n_species
)
) %>%
dplyr::group_by(
dplyr::across(dplyr::all_of(c(
group_by_deployments,
group_by_observations,
group_time_by
)))
) %>%
dplyr::summarise(
"n_scientificName" := dplyr::n_distinct(
.data$scientificName,
na.rm = TRUE
),
.groups = "keep"
)
# Define the formula for the number of events per deployment
formula_n_events_per_dep <- rlang::expr(
"n_events" := dplyr::n_distinct(.data$eventID, na.rm = TRUE)
Expand Down
1 change: 1 addition & 0 deletions man/camtraptor-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions tests/testthat/test-summarize_observations.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,58 @@ test_that("summarize_observations() returns correct summary for grouping by
rai_sum_count_df$rai_count)
})

test_that(
paste0("summarize_observations() returns n_scientificName equal to 1 or 0 ",
"when grouping by scientificName"
), {
skip_if_offline()
x <- example_dataset()
summary <- summarize_observations(x, group_by = "scientificName")
# A scientific name observed in more than one deployment is counted once
expect_identical(
summary$n_scientificName,
dplyr::if_else(is.na(summary$scientificName), 0L, 1L)
)
})

test_that(
paste0("summarize_observations() counts distinct scientific names over ",
"all deployments of a group"
), {
skip_if_offline()
x <- example_dataset()
# Group all deployments in one location
deployments(x) <- deployments(x) %>%
dplyr::mutate(locationName = "location")
summary <- summarize_observations(x, group_by = "locationName")

# Scientific names observed in more than one deployment are counted once
n_species <- x %>%
filter_observations(.data$observationLevel == "event") %>%
observations() %>%
dplyr::pull("scientificName") %>%
dplyr::n_distinct(na.rm = TRUE)
expect_identical(summary$n_scientificName, n_species)

# Same with time grouping
summary_year <- summarize_observations(
x, group_by = "locationName", group_time_by = "year"
)
n_species_year <- x %>%
filter_observations(.data$observationLevel == "event") %>%
observations() %>%
dplyr::group_by(
year = lubridate::floor_date(.data$eventStart, "year")
) %>%
dplyr::summarise(
n_scientificName = dplyr::n_distinct(.data$scientificName, na.rm = TRUE)
)
expect_identical(
summary_year$n_scientificName,
n_species_year$n_scientificName
)
})

testthat::test_that(
"Deployments without observations are not included in the summary", {
skip_if_offline()
Expand Down
Loading