diff --git a/R/merge_camtrapdp.R b/R/merge_camtrapdp.R index 6e63a030..b77f38a7 100644 --- a/R/merge_camtrapdp.R +++ b/R/merge_camtrapdp.R @@ -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 diff --git a/tests/testthat/test-merge_camtrapdp.R b/tests/testthat/test-merge_camtrapdp.R index b0075148..8709038b 100644 --- a/tests/testthat/test-merge_camtrapdp.R +++ b/tests/testthat/test-merge_camtrapdp.R @@ -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() @@ -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