Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify samplingDesign of second dataset is ignored when merging #150

Merged
merged 4 commits into from
Dec 19, 2024
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
14 changes: 14 additions & 0 deletions R/merge_camtrapdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ merge_camtrapdp <- function(x, y) {
}
prefixes <- c(x$name, y$name)

# Warn if samplingDesign of x and y are different
if (x$project$samplingDesign != y$project$samplingDesign) {
cli::cli_warn(
c(
"{.arg x} and {.arg y} have a different
{.field x$project$samplingDesign} ({.val {x$project$samplingDesign}} vs
{.val {y$project$samplingDesign}}).",
"i" = "The sampling design of {.arg x} will be used
({.val {x$project$samplingDesign}})."
),
class = "camtrapdp_warning_different_sampligndesign"
)
}

# Create xy from x
xy <- x

Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-merge_camtrapdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ test_that("merge_camtrapdp() returns a valid camtrapdp object", {
expect_no_error(check_camtrapdp(merge_camtrapdp(x, y)))
})

test_that("merge_camtrapdp() returns warning on non-identical samplingDesign", {
skip_if_offline()
x <- example_dataset()
x$name <- "x"
y <- x
y$name <- "y"
y$project$samplingDesign <- "opportunistic"

expect_warning(
merge_camtrapdp(x, y),
class = "camtrapdp_warning_different_sampligndesign"
)
})

test_that("merge_camtrapdp() returns error on missing/invalid/duplicate dataset
name(s)", {
skip_if_offline()
Expand Down Expand Up @@ -151,6 +165,7 @@ test_that("merge_camtrapdp() returns the expected datapackage.json when merging
download.file(y_url, zip_file, mode = "wb", quiet = TRUE)
unzip(zip_file, exdir = temp_dir)
y <- read_camtrapdp(datapackage_file)
y$project$samplingDesign <- "targeted" # To avoid warning
xy <- merge_camtrapdp(x, y)
xy$created <- NULL

Expand Down
Loading