From 3f85f5bbdea466ca69181d7eda6ae7e6f9d08b80 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 12:04:03 +0200 Subject: [PATCH 01/40] move `check_package()` outside of zzz.R --- R/check_package.R | 53 ++++++++++++++++++++++++++++++++++++++++++++++ R/zzz.R | 54 ----------------------------------------------- 2 files changed, 53 insertions(+), 54 deletions(-) create mode 100644 R/check_package.R diff --git a/R/check_package.R b/R/check_package.R new file mode 100644 index 00000000..625d80da --- /dev/null +++ b/R/check_package.R @@ -0,0 +1,53 @@ +#' Check validity camera trap data package +#' +#' Checks the validity of a camera trap data package. +#' It checks whether the data package is a list containing an element called +#' `data` with the following resources as tibble data frames: +#' - `observations` +#' - `multimedia` +#' - `deployments` +#' +#' @param package Camera trap data package +#' @param datapkg Deprecated. Use `package` instead. +#' @return A camera trap data package. +#' @noRd +check_package <- function(package = NULL, + datapkg = NULL, + function_name) { + if (lifecycle::is_present(datapkg) & !is.null(datapkg)) { + lifecycle::deprecate_warn( + when = "0.16.0", + what = paste0(function_name, "(datapkg = )"), + with = paste0(function_name, "(package = )") + ) + if (is.null(package)) { + package <- datapkg + } + } + # camera trap data package is a list + assertthat::assert_that(is.list(package)) + assertthat::assert_that(!is.data.frame(package)) + # check existence of an element called data + assertthat::assert_that("data" %in% names(package)) + # check validity data element of package: does it contain all 4 elements? + elements <- c("deployments", "media", "observations") + tables_absent <- names(elements)[ + !names(elements) %in% names(package$data) + ] + n_tables_absent <- length(tables_absent) + assertthat::assert_that(n_tables_absent == 0, + msg = glue::glue( + "Can't find {n_tables_absent} elements in data package: {tables_absent*}", + .transformer = collapse_transformer(sep = ", ", last = " and ") + ) + ) + + # check observations and deployments are data.frames + assertthat::assert_that(is.data.frame(package$data$observations)) + assertthat::assert_that(is.data.frame(package$data$deployments)) + # check multimedia is a data.frame (if imported, i.e. if not NULL) + if (!is.null(package$data$multimedia)) { + assertthat::assert_that(is.data.frame(package$data$multimedia)) + } + package +} diff --git a/R/zzz.R b/R/zzz.R index 3a772adf..c76a2746 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,57 +1,3 @@ -#' Check validity camera trap data package -#' -#' Checks the validity of a camera trap data package. -#' It checks whether the data package is a list containing an element called -#' `data` with the following resources as tibble data frames: -#' - `observations` -#' - `multimedia` -#' - `deployments` -#' -#' @param package Camera trap data package -#' @param datapkg Deprecated. Use `package` instead. -#' @return A camera trap data package. -#' @noRd -check_package <- function(package = NULL, - datapkg = NULL, - function_name) { - if (lifecycle::is_present(datapkg) & !is.null(datapkg)) { - lifecycle::deprecate_warn( - when = "0.16.0", - what = paste0(function_name, "(datapkg = )"), - with = paste0(function_name, "(package = )") - ) - if (is.null(package)) { - package <- datapkg - } - } - # camera trap data package is a list - assertthat::assert_that(is.list(package)) - assertthat::assert_that(!is.data.frame(package)) - # check existence of an element called data - assertthat::assert_that("data" %in% names(package)) - # check validity data element of package: does it contain all 4 elements? - elements <- c("deployments", "media", "observations") - tables_absent <- names(elements)[ - !names(elements) %in% names(package$data) - ] - n_tables_absent <- length(tables_absent) - assertthat::assert_that(n_tables_absent == 0, - msg = glue::glue( - "Can't find {n_tables_absent} elements in data package: {tables_absent*}", - .transformer = collapse_transformer(sep = ", ", last = " and ") - ) - ) - - # check observations and deployments are data.frames - assertthat::assert_that(is.data.frame(package$data$observations)) - assertthat::assert_that(is.data.frame(package$data$deployments)) - # check multimedia is a data.frame (if imported, i.e. if not NULL) - if (!is.null(package$data$multimedia)) { - assertthat::assert_that(is.data.frame(package$data$multimedia)) - } - package -} - #' Check input value against list of provided values #' #' Will return error message if an input value cannot be found in list of From e871c25720d9f9e27fdde6e6b5117ae9a6425c9a Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 12:09:07 +0200 Subject: [PATCH 02/40] rename multimedia to media overlooked from old version, discussed with Damiano Co-Authored-By: Damiano Oldoni --- R/check_package.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/check_package.R b/R/check_package.R index 625d80da..13bb191c 100644 --- a/R/check_package.R +++ b/R/check_package.R @@ -4,7 +4,7 @@ #' It checks whether the data package is a list containing an element called #' `data` with the following resources as tibble data frames: #' - `observations` -#' - `multimedia` +#' - `media` #' - `deployments` #' #' @param package Camera trap data package @@ -45,9 +45,9 @@ check_package <- function(package = NULL, # check observations and deployments are data.frames assertthat::assert_that(is.data.frame(package$data$observations)) assertthat::assert_that(is.data.frame(package$data$deployments)) - # check multimedia is a data.frame (if imported, i.e. if not NULL) - if (!is.null(package$data$multimedia)) { - assertthat::assert_that(is.data.frame(package$data$multimedia)) + # check media is a data.frame (if imported, i.e. if not NULL) + if (!is.null(package$data$media)) { + assertthat::assert_that(is.data.frame(package$data$media)) } package } From 06e3bfdaa2eecf94c7a8ff08b81410c99614d2d8 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 13:37:50 +0200 Subject: [PATCH 03/40] add comment on deprecation warning --- R/check_package.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/check_package.R b/R/check_package.R index 13bb191c..cfa70904 100644 --- a/R/check_package.R +++ b/R/check_package.R @@ -14,6 +14,8 @@ check_package <- function(package = NULL, datapkg = NULL, function_name) { + # Warn for usage of datapkg argument, mention (parent-) function name in error + # message if (lifecycle::is_present(datapkg) & !is.null(datapkg)) { lifecycle::deprecate_warn( when = "0.16.0", From e16686dc6eb541d4e1ef6843abf6c1882ba3cba5 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 13:38:22 +0200 Subject: [PATCH 04/40] When a package is valid, return TRUE --- R/check_package.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/check_package.R b/R/check_package.R index cfa70904..977a99de 100644 --- a/R/check_package.R +++ b/R/check_package.R @@ -51,5 +51,6 @@ check_package <- function(package = NULL, if (!is.null(package$data$media)) { assertthat::assert_that(is.data.frame(package$data$media)) } - package + # When all is good, return TRUE + return(TRUE) } From 4449ff6f3d7b11bcc6fb09ab52c61ed5bce5089f Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 14:23:40 +0200 Subject: [PATCH 05/40] test deprecation warning --- tests/testthat/test-check_package.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/testthat/test-check_package.R diff --git a/tests/testthat/test-check_package.R b/tests/testthat/test-check_package.R new file mode 100644 index 00000000..6bae3039 --- /dev/null +++ b/tests/testthat/test-check_package.R @@ -0,0 +1,12 @@ +test_that("check_package() returns depreciation warning on datapkg argument", { + expect_warning( + check_package(datapkg = mica, function_name = "function_name_here"), + regexp = "The `datapkg` argument of `function_name_here()` is deprecated as of camtraptor 0.16.0.", + fixed = TRUE + ) +}) + + +test_that("check_package() returns TRUE on valid package", { + expect_true(check_package(mica)) +}) From ed425774193fdd335c980e3b0fc042e17359c2f6 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 14:24:08 +0200 Subject: [PATCH 06/40] test package class --- tests/testthat/test-check_package.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/testthat/test-check_package.R b/tests/testthat/test-check_package.R index 6bae3039..fbc6cb5a 100644 --- a/tests/testthat/test-check_package.R +++ b/tests/testthat/test-check_package.R @@ -6,6 +6,19 @@ test_that("check_package() returns depreciation warning on datapkg argument", { ) }) +test_that("check_package() returns error when package is not a list", { + expect_error( + check_package("not a list!"), + regexp = "package is not a list", + fixed = TRUE + ) + expect_error( + check_package(data.frame(letters = c("a","b","c"), numbers = c(pi,2*pi,3*pi))), + regexp = "package is not a list", + fixed = TRUE + ) +}) + test_that("check_package() returns TRUE on valid package", { expect_true(check_package(mica)) From a541ff528351e0c74e487bc92867bc0b7dd93dd5 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 14:24:18 +0200 Subject: [PATCH 07/40] test for missing data elements --- tests/testthat/test-check_package.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/testthat/test-check_package.R b/tests/testthat/test-check_package.R index fbc6cb5a..9d942d89 100644 --- a/tests/testthat/test-check_package.R +++ b/tests/testthat/test-check_package.R @@ -19,6 +19,14 @@ test_that("check_package() returns error when package is not a list", { ) }) +test_that("check_package() returns error on missing data", { + expect_error( + check_package(purrr::discard_at(mica,at = "data")), + regexp = "data element is missing from package", + fixed = TRUE + ) +}) + test_that("check_package() returns TRUE on valid package", { expect_true(check_package(mica)) From 2121af87d8c22a3a1db2727114d8086adf07bc1d Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 14:24:38 +0200 Subject: [PATCH 08/40] test for number/identity of data elements --- tests/testthat/test-check_package.R | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/testthat/test-check_package.R b/tests/testthat/test-check_package.R index 9d942d89..f49158f1 100644 --- a/tests/testthat/test-check_package.R +++ b/tests/testthat/test-check_package.R @@ -27,6 +27,23 @@ test_that("check_package() returns error on missing data", { ) }) +test_that("check_package() returns error if not all elements are present", { + mica_no_media <- mica + mica_no_media$data$media <- NULL + expect_error( + check_package(mica_no_media), + regexp = "Can't find 1 elements in data package: media", + fixed = TRUE + ) + mica_no_media_no_obs <- mica_no_media + mica_no_media_no_obs$data$observations <- NULL + expect_error( + check_package(mica_no_media_no_obs), + regexp = "Can't find 2 elements in data package: media and observations", + fixed = TRUE + ) +}) + test_that("check_package() returns TRUE on valid package", { expect_true(check_package(mica)) From e0f2e5909509cba28c332d42f6a719fc75adee26 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 14:24:55 +0200 Subject: [PATCH 09/40] add error messages --- R/check_package.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R/check_package.R b/R/check_package.R index 977a99de..3cf13158 100644 --- a/R/check_package.R +++ b/R/check_package.R @@ -28,10 +28,12 @@ check_package <- function(package = NULL, } # camera trap data package is a list assertthat::assert_that(is.list(package)) - assertthat::assert_that(!is.data.frame(package)) + assertthat::assert_that(!is.data.frame(package), + msg = "package is not a list") # check existence of an element called data - assertthat::assert_that("data" %in% names(package)) - # check validity data element of package: does it contain all 4 elements? + assertthat::assert_that("data" %in% names(package), + msg = "data element is missing from package") + # check validity data element of package: does it contain all 3 elements? elements <- c("deployments", "media", "observations") tables_absent <- names(elements)[ !names(elements) %in% names(package$data) From 36871af5405e52dad80742154e1514a04e707211 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 14:25:55 +0200 Subject: [PATCH 10/40] refactor so it works test was failing --- R/check_package.R | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/R/check_package.R b/R/check_package.R index 3cf13158..53e1e4a1 100644 --- a/R/check_package.R +++ b/R/check_package.R @@ -35,16 +35,15 @@ check_package <- function(package = NULL, msg = "data element is missing from package") # check validity data element of package: does it contain all 3 elements? elements <- c("deployments", "media", "observations") - tables_absent <- names(elements)[ - !names(elements) %in% names(package$data) - ] - n_tables_absent <- length(tables_absent) - assertthat::assert_that(n_tables_absent == 0, - msg = glue::glue( - "Can't find {n_tables_absent} elements in data package: {tables_absent*}", - .transformer = collapse_transformer(sep = ", ", last = " and ") - ) - ) + tables_absent <- dplyr::setdiff(elements, names(package$data)) + assertthat::assert_that( + assertthat::are_equal(elements, + names(package$data)), + msg = glue::glue( + "Can't find {n_tables_absent} elements in data package: {tables_absent*}", + .transformer = collapse_transformer(sep = ", ", last = " and "), + n_tables_absent = length(tables_absent) + )) # check observations and deployments are data.frames assertthat::assert_that(is.data.frame(package$data$observations)) From 81c837103e362774fdcee93e2fa00af35252b401 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 14:56:52 +0200 Subject: [PATCH 11/40] test for data.frame elements --- tests/testthat/test-check_package.R | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/testthat/test-check_package.R b/tests/testthat/test-check_package.R index f49158f1..a87597c3 100644 --- a/tests/testthat/test-check_package.R +++ b/tests/testthat/test-check_package.R @@ -44,6 +44,27 @@ test_that("check_package() returns error if not all elements are present", { ) }) +test_that("check_package() returns error if observations is not a data.frame", { + mica_listed <- mica + mica_listed$data$observations <- as.list(mica_listed$data$observations) + + expect_error( + check_package(mica_listed), + regexp = "package$data$observations is not a data frame", + fixed = TRUE + ) +}) + +test_that("check_package() returns error if deployments is not a data.frame", { + mica_listed <- mica + mica_listed$data$deployments <- as.list(mica_listed$data$deployments) + expect_error( + check_package(mica_listed), + regexp = "package$data$deployments is not a data frame", + fixed = TRUE + ) +}) + test_that("check_package() returns TRUE on valid package", { expect_true(check_package(mica)) From 9e4f5ccdd1ecda6cf7ceb3f40a9392f2a00a1c38 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 14:57:03 +0200 Subject: [PATCH 12/40] test for no error if media is not imported --- tests/testthat/test-check_package.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/testthat/test-check_package.R b/tests/testthat/test-check_package.R index a87597c3..556df9ea 100644 --- a/tests/testthat/test-check_package.R +++ b/tests/testthat/test-check_package.R @@ -65,6 +65,12 @@ test_that("check_package() returns error if deployments is not a data.frame", { ) }) +test_that("check_package() doesn't return an error on a NULL media object", { + # the case when media is not imported + mica_null_media <- mica + mica_null_media$data["media"] <- list(NULL) + expect_true(check_package(mica_null_media)) +}) test_that("check_package() returns TRUE on valid package", { expect_true(check_package(mica)) From efb23d3243c875f9ec14855254d64d5cb6c05929 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 14:57:52 +0200 Subject: [PATCH 13/40] test for error when media is not a data.frame --- tests/testthat/test-check_package.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/testthat/test-check_package.R b/tests/testthat/test-check_package.R index 556df9ea..53a17641 100644 --- a/tests/testthat/test-check_package.R +++ b/tests/testthat/test-check_package.R @@ -72,6 +72,16 @@ test_that("check_package() doesn't return an error on a NULL media object", { expect_true(check_package(mica_null_media)) }) +test_that("check_package() returns error if media is not a data.frame", { + mica_listed <- mica + mica_listed$data$media <- as.list(mica_listed$data$media) + expect_error( + check_package(mica_listed), + regexp = "package$data$media is not a data frame", + fixed = TRUE + ) +}) + test_that("check_package() returns TRUE on valid package", { expect_true(check_package(mica)) }) From b444abe262640ec55ac5e872f873cc3525f51f01 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 14:58:52 +0200 Subject: [PATCH 14/40] stylr --- tests/testthat/test-check_package.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-check_package.R b/tests/testthat/test-check_package.R index 53a17641..01dedd7c 100644 --- a/tests/testthat/test-check_package.R +++ b/tests/testthat/test-check_package.R @@ -13,7 +13,7 @@ test_that("check_package() returns error when package is not a list", { fixed = TRUE ) expect_error( - check_package(data.frame(letters = c("a","b","c"), numbers = c(pi,2*pi,3*pi))), + check_package(data.frame(letters = c("a", "b", "c"), numbers = c(pi, 2 * pi, 3 * pi))), regexp = "package is not a list", fixed = TRUE ) @@ -21,7 +21,7 @@ test_that("check_package() returns error when package is not a list", { test_that("check_package() returns error on missing data", { expect_error( - check_package(purrr::discard_at(mica,at = "data")), + check_package(purrr::discard_at(mica, at = "data")), regexp = "data element is missing from package", fixed = TRUE ) @@ -47,7 +47,7 @@ test_that("check_package() returns error if not all elements are present", { test_that("check_package() returns error if observations is not a data.frame", { mica_listed <- mica mica_listed$data$observations <- as.list(mica_listed$data$observations) - + expect_error( check_package(mica_listed), regexp = "package$data$observations is not a data frame", From 2c9e2b9a9a593215a3f0e2bf14894b8065f11c65 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 15:09:06 +0200 Subject: [PATCH 15/40] no longer assign check_package() to validate --- R/check_species.R | 3 ++- R/get_cam_op.R | 2 +- R/get_custom_effort.R | 2 +- R/get_effort.R | 2 +- R/get_n_individuals.R | 2 +- R/get_n_obs.R | 2 +- R/get_n_species.R | 2 +- R/get_rai.R | 4 ++-- R/get_record_table.R | 2 +- R/get_scientific_name.R | 2 +- R/get_species.R | 2 +- R/map_dep.R | 2 +- R/zzz.R | 2 +- 13 files changed, 15 insertions(+), 14 deletions(-) diff --git a/R/check_species.R b/R/check_species.R index c7ba8181..0911399b 100644 --- a/R/check_species.R +++ b/R/check_species.R @@ -38,7 +38,8 @@ check_species <- function(package = NULL, arg_name = "species", datapkg = lifecycle::deprecated()) { # Check camera trap data package - package <- check_package(package, datapkg, "check_species") + check_package(package, datapkg, "check_species") + assertthat::assert_that( !is.null(species) & length(species) > 0, msg = "`species` parameter must be specified" diff --git a/R/get_cam_op.R b/R/get_cam_op.R index c90fa783..00ab37a5 100644 --- a/R/get_cam_op.R +++ b/R/get_cam_op.R @@ -49,7 +49,7 @@ get_cam_op <- function(package = NULL, use_prefix = FALSE, datapkg = NULL) { # check camera trap data package - package <- check_package(package, datapkg, "get_cam_op") + check_package(package, datapkg, "get_cam_op") # Check that station_col is one of the columns in deployments assertthat::assert_that( diff --git a/R/get_custom_effort.R b/R/get_custom_effort.R index e0041a0e..35c3a398 100644 --- a/R/get_custom_effort.R +++ b/R/get_custom_effort.R @@ -116,7 +116,7 @@ get_custom_effort <- function(package = NULL, check_value(group_by, group_bys, "group_by", null_allowed = TRUE) # check camera trap data package - package <- check_package(package, datapkg, "get_custom_effort") + check_package(package, datapkg, "get_custom_effort") # get deployments deployments <- package$data$deployments diff --git a/R/get_effort.R b/R/get_effort.R index 4165dc14..5c6f03c0 100644 --- a/R/get_effort.R +++ b/R/get_effort.R @@ -42,7 +42,7 @@ get_effort <- function(package = NULL, check_value(unit, units, "unit", null_allowed = FALSE) # check camera trap data package - package <- check_package(package, datapkg, "get_effort") + check_package(package, datapkg, "get_effort") # apply filtering package$data$deployments <- apply_filter_predicate( diff --git a/R/get_n_individuals.R b/R/get_n_individuals.R index 0cd1a27a..6874ae28 100644 --- a/R/get_n_individuals.R +++ b/R/get_n_individuals.R @@ -67,7 +67,7 @@ get_n_individuals <- function(package = NULL, life_stage = NULL, datapkg = lifecycle::deprecated()) { # check input data package - package <- check_package(package, datapkg, "get_n_individuals") + check_package(package, datapkg, "get_n_individuals") # avoid to call variables like column names to make life easier using filter() sex_value <- sex diff --git a/R/get_n_obs.R b/R/get_n_obs.R index 4e7e4a7d..ddf97a15 100644 --- a/R/get_n_obs.R +++ b/R/get_n_obs.R @@ -64,7 +64,7 @@ get_n_obs <- function(package = NULL, life_stage = NULL, datapkg = lifecycle::deprecated()) { # check input data package - package <- check_package(package, datapkg, "get_n_obs") + check_package(package, datapkg, "get_n_obs") # avoid to call variables like column names to make life easier using filter() sex_value <- sex diff --git a/R/get_n_species.R b/R/get_n_species.R index 473fd792..94349b13 100644 --- a/R/get_n_species.R +++ b/R/get_n_species.R @@ -23,7 +23,7 @@ get_n_species <- function(package = NULL, ..., datapkg = lifecycle::deprecated()) { # check input data package - package <- check_package(package, datapkg, "get_n_species") + check_package(package, datapkg, "get_n_species") # extract observations and deployments observations <- package$data$observations diff --git a/R/get_rai.R b/R/get_rai.R index 21c67f37..63d57e80 100644 --- a/R/get_rai.R +++ b/R/get_rai.R @@ -58,7 +58,7 @@ get_rai <- function(package = NULL, life_stage = NULL, datapkg = lifecycle::deprecated()) { # check camera trap data package - package <- check_package(package, datapkg, "get_rai") + check_package(package, datapkg, "get_rai") get_rai_primitive(package, ..., use = "n_obs", @@ -135,7 +135,7 @@ get_rai_individuals <- function(package = NULL, life_stage = NULL, datapkg = lifecycle::deprecated()) { # check camera trap data package - package <- check_package(package, datapkg, "get_rai_individuals") + check_package(package, datapkg, "get_rai_individuals") get_rai_primitive(package, ..., use = "n_individuals", species = species, diff --git a/R/get_record_table.R b/R/get_record_table.R index 39b12a9f..40d014c7 100644 --- a/R/get_record_table.R +++ b/R/get_record_table.R @@ -102,7 +102,7 @@ get_record_table <- function(package = NULL, removeDuplicateRecords = TRUE, datapkg = lifecycle::deprecated()) { # check data package - package <- check_package(package, datapkg, "get_record_table") + check_package(package, datapkg, "get_record_table") # check stationCol is a valid column name assertthat::assert_that( diff --git a/R/get_scientific_name.R b/R/get_scientific_name.R index b79b304a..29329a47 100644 --- a/R/get_scientific_name.R +++ b/R/get_scientific_name.R @@ -35,7 +35,7 @@ get_scientific_name <- function(package = NULL, vernacular_name, datapkg = lifecycle::deprecated()) { - package <- check_package(package, datapkg, "get_scientific_name") + check_package(package, datapkg, "get_scientific_name") all_sn_vn <- get_species(package) # get vernacular names for check diff --git a/R/get_species.R b/R/get_species.R index 924d068a..3ee20b3d 100644 --- a/R/get_species.R +++ b/R/get_species.R @@ -14,7 +14,7 @@ #' get_species(mica) get_species <- function(package = NULL, datapkg = lifecycle::deprecated()) { # Check camera trap data package - package <- check_package(package, datapkg, "get_species") + check_package(package, datapkg, "get_species") # Get taxonomic information from package metadata if (!"taxonomic" %in% names(package)) { diff --git a/R/map_dep.R b/R/map_dep.R index 5027c5a9..606424df 100644 --- a/R/map_dep.R +++ b/R/map_dep.R @@ -317,7 +317,7 @@ map_dep <- function(package = NULL, datapkg = lifecycle::deprecated()) { # check camera trap data package - package <- check_package(package, datapkg, "map_dep") + check_package(package, datapkg, "map_dep") # define possible feature values features <- c( diff --git a/R/zzz.R b/R/zzz.R index c76a2746..5430ce9a 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -154,7 +154,7 @@ get_dep_no_obs <- function(package = NULL, datapkg = lifecycle::deprecated()) { # check input camera trap data package - package <- check_package(package, datapkg, "get_dep_no_obs") + check_package(package, datapkg, "get_dep_no_obs") # extract observations and deployments observations <- package$data$observations From 80432181fb80f4bd63ccd193aa990139a3c6e123 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 15:22:27 +0200 Subject: [PATCH 16/40] silence messages during testing --- tests/testthat/test-check_species.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-check_species.R b/tests/testthat/test-check_species.R index 155b4ae2..45445da3 100644 --- a/tests/testthat/test-check_species.R +++ b/tests/testthat/test-check_species.R @@ -40,19 +40,19 @@ test_that("Multiput scientific names are allowed", { test_that("Function works with vernacular names", { vn_names <- c("beech marten", "mallard") - species <- check_species(mica, vn_names) + species <- suppressMessages(check_species(mica, vn_names)) testthat::expect_equal(species, c("Martes foina", "Anas platyrhynchos")) }) test_that("Functions works well with vernacular names of different languages", { vn_names <- c("beech marten", "wilde eend") - species <- check_species(mica, vn_names) + species <- suppressMessages(check_species(mica, vn_names)) testthat::expect_equal(species, c("Martes foina", "Anas platyrhynchos")) }) test_that("Functions works with a mix of scientific and vernacular names", { mixed_names <- c("mallard", "steenmarter", "Castor fiber") - species <- check_species(mica, mixed_names) + species <- suppressMessages(check_species(mica, mixed_names)) testthat::expect_equal( species, c( @@ -69,7 +69,7 @@ test_that("Taxon IDs are not allowed", { }) test_that("Functions works case insensitively", { - vn_name <- check_species(mica, c("MallARD")) + vn_name <- suppressMessages(check_species(mica, c("MallARD"))) species <- check_species(mica, vn_name) testthat::expect_equal(species, "Anas platyrhynchos") }) From 7e6a4397db8213100fc84d1502fe40be812f31fa Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 16:18:29 +0200 Subject: [PATCH 17/40] remove test covered by test-check_package.R --- tests/testthat/test-check_species.R | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/testthat/test-check_species.R b/tests/testthat/test-check_species.R index 45445da3..74bff7d1 100644 --- a/tests/testthat/test-check_species.R +++ b/tests/testthat/test-check_species.R @@ -73,12 +73,3 @@ test_that("Functions works case insensitively", { species <- check_species(mica, vn_name) testthat::expect_equal(species, "Anas platyrhynchos") }) - -test_that("Argument datapkg is deprecated: warning returned", { - testthat::expect_warning( - rlang::with_options( - lifecycle_verbosity = "warning", - check_species(datapkg = mica, species = "Anas strepera") - ) - ) -}) From 390f95dde3910775155a323ea8413e22ad13712a Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 16:18:29 +0200 Subject: [PATCH 18/40] remove test covered by test-check_package.R The usage of the `datapkg` argument is tested in test-check_package.R, I don't think it needs to be tested for every function individually. --- tests/testthat/test-check_species.R | 9 --------- tests/testthat/test-get_cam_op.R | 9 --------- tests/testthat/test-get_custom_effort.R | 9 --------- tests/testthat/test-get_effort.R | 9 --------- tests/testthat/test-get_n_individuals.R | 9 --------- tests/testthat/test-get_n_obs.R | 9 --------- tests/testthat/test-get_n_species.R | 9 --------- tests/testthat/test-get_rai.R | 9 --------- tests/testthat/test-get_rai_individuals.R | 9 --------- tests/testthat/test-get_record_table.R | 9 --------- tests/testthat/test-get_scientific_name.R | 9 --------- 11 files changed, 99 deletions(-) diff --git a/tests/testthat/test-check_species.R b/tests/testthat/test-check_species.R index 45445da3..74bff7d1 100644 --- a/tests/testthat/test-check_species.R +++ b/tests/testthat/test-check_species.R @@ -73,12 +73,3 @@ test_that("Functions works case insensitively", { species <- check_species(mica, vn_name) testthat::expect_equal(species, "Anas platyrhynchos") }) - -test_that("Argument datapkg is deprecated: warning returned", { - testthat::expect_warning( - rlang::with_options( - lifecycle_verbosity = "warning", - check_species(datapkg = mica, species = "Anas strepera") - ) - ) -}) diff --git a/tests/testthat/test-get_cam_op.R b/tests/testthat/test-get_cam_op.R index 3bd2c88a..a8800b5b 100644 --- a/tests/testthat/test-get_cam_op.R +++ b/tests/testthat/test-get_cam_op.R @@ -143,12 +143,3 @@ test_that("filtering predicates are allowed and work well", { filtered_cam_op_matrix <- get_cam_op(mica, pred_lt("longitude", 4.0)) expect_equal(rownames(filtered_cam_op_matrix), "Mica Viane") }) - -test_that("Argument datapkg is deprecated: warning returned", { - expect_warning( - rlang::with_options( - lifecycle_verbosity = "warning", - get_cam_op(datapkg = mica) - ) - ) -}) diff --git a/tests/testthat/test-get_custom_effort.R b/tests/testthat/test-get_custom_effort.R index a83aea15..acdbb284 100644 --- a/tests/testthat/test-get_custom_effort.R +++ b/tests/testthat/test-get_custom_effort.R @@ -178,12 +178,3 @@ test_that("check effort and unit values", { # unit value is equal to day if unit value is set to "day" expect_equal(unique(tot_effort_days$unit), "day") }) - -test_that("Argument datapkg is deprecated: warning returned", { - expect_warning( - rlang::with_options( - lifecycle_verbosity = "warning", - get_custom_effort(datapkg = mica) - ) - ) -}) diff --git a/tests/testthat/test-get_effort.R b/tests/testthat/test-get_effort.R index 572b90a9..c9af3cab 100644 --- a/tests/testthat/test-get_effort.R +++ b/tests/testthat/test-get_effort.R @@ -75,12 +75,3 @@ testthat::test_that("get_effort returns the right number of rows", { n_all_deployments ) }) - -testthat::test_that("Argument datapkg is deprecated: warning returned", { - testthat::expect_warning( - rlang::with_options( - lifecycle_verbosity = "warning", - get_effort(datapkg = mica) - ) - ) -}) diff --git a/tests/testthat/test-get_n_individuals.R b/tests/testthat/test-get_n_individuals.R index ee7e4ad0..ff66adc1 100644 --- a/tests/testthat/test-get_n_individuals.R +++ b/tests/testthat/test-get_n_individuals.R @@ -244,12 +244,3 @@ test_that("error returned if life stage or sex is not present", { expect_error(get_n_individuals(mica, life_stage = "bad")) expect_error(get_n_individuals(mica, sex = "bad")) }) - -test_that("Argument datapkg is deprecated: warning returned", { - expect_warning( - rlang::with_options( - lifecycle_verbosity = "warning", - get_n_individuals(datapkg = mica) - ) - ) -}) diff --git a/tests/testthat/test-get_n_obs.R b/tests/testthat/test-get_n_obs.R index e7d51b1b..4cde9c3f 100644 --- a/tests/testthat/test-get_n_obs.R +++ b/tests/testthat/test-get_n_obs.R @@ -243,15 +243,6 @@ test_that(paste( expect_true(all(species_value %in% n_obs$scientificName)) }) -test_that("Argument datapkg is deprecated: warning returned", { - expect_warning( - rlang::with_options( - lifecycle_verbosity = "warning", - get_n_obs(datapkg = mica) - ) - ) -}) - test_that("Filter by date of deployments via predicates works correctly", { end_date <- as.Date("2021-01-01", format = "%Y-%m-%d") mica_with_obs_filtered_manually <- mica diff --git a/tests/testthat/test-get_n_species.R b/tests/testthat/test-get_n_species.R index d2638c77..54b2adf6 100644 --- a/tests/testthat/test-get_n_species.R +++ b/tests/testthat/test-get_n_species.R @@ -19,12 +19,3 @@ test_that("get_n_species returns the right dataframe", { ) ) }) - -test_that("Argument datapkg is deprecated: warning returned", { - expect_warning( - rlang::with_options( - lifecycle_verbosity = "warning", - get_n_species(datapkg = mica) - ) - ) -}) diff --git a/tests/testthat/test-get_rai.R b/tests/testthat/test-get_rai.R index 8e43fd49..851991ae 100644 --- a/tests/testthat/test-get_rai.R +++ b/tests/testthat/test-get_rai.R @@ -94,12 +94,3 @@ test_that("life_stage filters data correctly", { ignore_attr = TRUE ) }) - -test_that("Argument datapkg is deprecated: warning returned", { - expect_warning( - rlang::with_options( - lifecycle_verbosity = "warning", - get_rai(datapkg = mica) - ) - ) -}) diff --git a/tests/testthat/test-get_rai_individuals.R b/tests/testthat/test-get_rai_individuals.R index a3380024..b6df1be4 100644 --- a/tests/testthat/test-get_rai_individuals.R +++ b/tests/testthat/test-get_rai_individuals.R @@ -94,12 +94,3 @@ test_that("life_stage filters data correctly", { ignore_attr = TRUE ) }) - -test_that("Argument datapkg is deprecated: warning returned", { - expect_warning( - rlang::with_options( - lifecycle_verbosity = "warning", - get_rai_individuals(datapkg = mica) - ) - ) -}) diff --git a/tests/testthat/test-get_record_table.R b/tests/testthat/test-get_record_table.R index cb07270e..a39f725d 100644 --- a/tests/testthat/test-get_record_table.R +++ b/tests/testthat/test-get_record_table.R @@ -191,12 +191,3 @@ test_that("filtering predicates are allowed and work well", { dplyr::pull(locationName) testthat::expect_identical(stations, stations_calculate) }) - -test_that("Argument datapkg is deprecated: warning returned", { - expect_warning( - rlang::with_options( - lifecycle_verbosity = "warning", - get_record_table(datapkg = mica) - ) - ) -}) diff --git a/tests/testthat/test-get_scientific_name.R b/tests/testthat/test-get_scientific_name.R index b4d9aec9..43ed331b 100644 --- a/tests/testthat/test-get_scientific_name.R +++ b/tests/testthat/test-get_scientific_name.R @@ -18,12 +18,3 @@ test_that("Functions works case insensitively", { sc_names <- get_scientific_name(mica, c("beeCH MArten")) expect_equal(sc_names, c("Martes foina")) }) - -test_that("Argument datapkg is deprecated: warning returned", { - expect_warning( - rlang::with_options( - lifecycle_verbosity = "warning", - get_scientific_name(datapkg = mica, vernacular_name = "beech marten") - ) - ) -}) From 9aa6cf06e96818c844a0f87f3fb9bcb6d148cedd Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 16:25:38 +0200 Subject: [PATCH 19/40] `check_package()` now returns TRUE on a valid package --- tests/testthat/test-read_wi.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-read_wi.R b/tests/testthat/test-read_wi.R index 90a69e82..9d170803 100644 --- a/tests/testthat/test-read_wi.R +++ b/tests/testthat/test-read_wi.R @@ -6,5 +6,5 @@ test_that("read_wi() returns error when files are not found", { }) test_that("read_wi() returns a valid package", { - expect_type(camtraptor:::check_package(read_wi("data")), "list") + expect_true(camtraptor:::check_package(read_wi("data"))) }) From 1d40a023af29c874ea0d401efd089179366d9965 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 14 Jul 2023 16:52:49 +0200 Subject: [PATCH 20/40] silence messages in testing output --- tests/testthat/test-get_cam_op.R | 4 +- tests/testthat/test-get_custom_effort.R | 8 +-- tests/testthat/test-get_n_individuals.R | 45 ++++++++-------- tests/testthat/test-get_n_obs.R | 66 ++++++++++++++--------- tests/testthat/test-get_rai.R | 26 ++++++--- tests/testthat/test-get_rai_individuals.R | 30 ++++++++--- tests/testthat/test-get_record_table.R | 37 +++++++------ 7 files changed, 134 insertions(+), 82 deletions(-) diff --git a/tests/testthat/test-get_cam_op.R b/tests/testthat/test-get_cam_op.R index a8800b5b..1c0afa65 100644 --- a/tests/testthat/test-get_cam_op.R +++ b/tests/testthat/test-get_cam_op.R @@ -140,6 +140,8 @@ test_that( ) test_that("filtering predicates are allowed and work well", { - filtered_cam_op_matrix <- get_cam_op(mica, pred_lt("longitude", 4.0)) + filtered_cam_op_matrix <- suppressMessages( + get_cam_op(mica, pred_lt("longitude", 4.0)) + ) expect_equal(rownames(filtered_cam_op_matrix), "Mica Viane") }) diff --git a/tests/testthat/test-get_custom_effort.R b/tests/testthat/test-get_custom_effort.R index acdbb284..b6470b31 100644 --- a/tests/testthat/test-get_custom_effort.R +++ b/tests/testthat/test-get_custom_effort.R @@ -163,9 +163,11 @@ test_that("right columns, cols types, right relative number of rows", { test_that("check effort and unit values", { tot_effort <- get_custom_effort(mica) # filtering deployments reduces effort value - filter_deploys <- get_custom_effort(mica, - pred_gte("latitude", 51.18), - group_by = "year" + filter_deploys <- suppressMessages( + get_custom_effort(mica, + pred_gte("latitude", 51.18), + group_by = "year" + ) ) expect_lt(filter_deploys$effort, tot_effort$effort) diff --git a/tests/testthat/test-get_n_individuals.R b/tests/testthat/test-get_n_individuals.R index ff66adc1..ee12f289 100644 --- a/tests/testthat/test-get_n_individuals.R +++ b/tests/testthat/test-get_n_individuals.R @@ -1,9 +1,8 @@ test_that("get_n_individuals returns the right structure of dataframe", { - # species arg specified - output_anas_platyrhyncos <- get_n_individuals(mica, + output_anas_platyrhyncos <- suppressMessages(get_n_individuals(mica, species = "Anas platyrhynchos" - ) + )) # type list expect_type(output_anas_platyrhyncos, "list") @@ -64,9 +63,9 @@ test_that(paste( n_deployments <- length(deployments) # calculate get_n_individuals for a species undetected in one deployment - output_martes_foina <- get_n_individuals(mica, + output_martes_foina <- suppressMessages(get_n_individuals(mica, species = "Martes foina" - ) + )) # number of rows should be equal to number of deployments expect_equal(nrow(output_martes_foina), n_deployments) @@ -104,8 +103,8 @@ test_that("species = 'all' returns the same of using a vector with all species", test_that("species is case insensitive", { expect_equal( - get_n_individuals(mica, species = "Anas platyrhynchos"), - get_n_individuals(mica, species = toupper("Anas platyrhynchos")) + suppressMessages(get_n_individuals(mica, species = "Anas platyrhynchos")), + suppressMessages(get_n_individuals(mica, species = toupper("Anas platyrhynchos"))) ) }) @@ -113,15 +112,14 @@ test_that(paste( "species accepts use of common names and return", "the same as using scientic name" ), { - # define scientific name scn <- "Anas platyrhynchos" # define correspondent vernacular name vn <- "Mallard" # get number of individuals for both cases - output_anas_platyrhyncos <- get_n_individuals(mica, species = scn) - output_mallard <- get_n_individuals(mica, species = vn) + output_anas_platyrhyncos <- suppressMessages(get_n_individuals(mica, species = scn)) + output_mallard <- suppressMessages(get_n_individuals(mica, species = vn)) # same outputs expect_equal(output_anas_platyrhyncos, output_mallard) @@ -129,9 +127,9 @@ test_that(paste( test_that("if subset of species is specified, less individuals are returned", { output_all_species <- get_n_individuals(mica) - output_anas_platyrhyncos <- get_n_individuals(mica, + output_anas_platyrhyncos <- suppressMessages(get_n_individuals(mica, species = "Anas platyrhynchos" - ) + )) expect_true(sum(output_all_species$n) >= sum(output_anas_platyrhyncos$n)) }) @@ -166,10 +164,10 @@ test_that("number of individuals is equal to sum of counts", { dplyr::filter(scientificName == species) %>% dplyr::pull(count) %>% sum() - n_individuals <- get_n_individuals(mica, + n_individuals <- suppressMessages(get_n_individuals(mica, species = "Mallard", pred("deploymentID", deploy_id) - ) + )) expect_equal(n_individuals$n, n_individuals_via_count) }) @@ -180,7 +178,8 @@ test_that("sex filters data correctly", { dplyr::filter(sex == sex_value) %>% dplyr::pull(count) %>% sum() - n_individuals_females <- get_n_individuals(mica, species = NULL, sex = sex_value) + n_individuals_females <- + suppressMessages(get_n_individuals(mica, species = NULL, sex = sex_value)) tot_n_individuals_females <- sum(n_individuals_females$n) expect_equal(tot_n_individuals_females, n_individuals_via_count) expect_equal(nrow(n_individuals_females), nrow(mica$data$deployments)) @@ -193,10 +192,10 @@ test_that("multiple sex values allowed", { dplyr::filter(sex %in% sex_value) %>% dplyr::pull(count) %>% sum() - n_individuals_females_undefined <- get_n_individuals(mica, + n_individuals_females_undefined <- suppressMessages(get_n_individuals(mica, species = NULL, sex = sex_value - ) + )) tot_n_individuals_females_undefined <- sum(n_individuals_females_undefined$n) expect_equal( tot_n_individuals_females_undefined, @@ -215,7 +214,9 @@ test_that("life stage filters data correctly", { dplyr::filter(lifeStage == life_stage_value) %>% dplyr::pull(count) %>% sum() - n_individuals_juvenile <- get_n_individuals(mica, species = NULL, life_stage = life_stage_value) + n_individuals_juvenile <- suppressMessages( + get_n_individuals(mica, species = NULL, life_stage = life_stage_value) + ) tot_n_individuals_juvenile <- sum(n_individuals_juvenile$n) expect_equal(tot_n_individuals_juvenile, n_individuals_juvenile_via_count) expect_equal(nrow(n_individuals_juvenile), nrow(mica$data$deployments)) @@ -228,9 +229,11 @@ test_that("multiple age values allowed", { dplyr::filter(lifeStage %in% life_stage_value) %>% dplyr::pull(count) %>% sum() - n_individuals_juvenile_adult <- get_n_individuals(mica, - species = NULL, - life_stage = life_stage_value + n_individuals_juvenile_adult <- suppressMessages( + get_n_individuals(mica, + species = NULL, + life_stage = life_stage_value + ) ) tot_n_individuals_juvenile_adult <- sum(n_individuals_juvenile_adult$n) expect_equal( diff --git a/tests/testthat/test-get_n_obs.R b/tests/testthat/test-get_n_obs.R index 4cde9c3f..6629aeea 100644 --- a/tests/testthat/test-get_n_obs.R +++ b/tests/testthat/test-get_n_obs.R @@ -1,8 +1,9 @@ test_that("get_n_obs returns the right structure of dataframe", { - # species arg specified - output_anas_platyrhyncos <- get_n_obs(mica, - species = "Anas platyrhynchos" + output_anas_platyrhyncos <- suppressMessages( + get_n_obs(mica, + species = "Anas platyrhynchos" + ) ) # type list @@ -64,8 +65,10 @@ test_that(paste( n_deployments <- length(deployments) # calculate get_n_obs for a species undetected in one deployment - output_ondatra_zibethicus <- get_n_obs(mica, - species = "Anas strepera" + output_ondatra_zibethicus <- suppressMessages( + get_n_obs(mica, + species = "Anas strepera" + ) ) # number of rows should be equal to number of deployments @@ -104,8 +107,10 @@ test_that("species = 'all' returns the same of using a vector with all species", test_that("species is case insensitive", { expect_equal( - get_n_obs(mica, species = "Anas platyrhynchos"), - get_n_obs(mica, species = toupper("ANAS platYrhyncHOS")) + suppressMessages( + get_n_obs(mica, species = "Anas platyrhynchos") + ), + suppressMessages(get_n_obs(mica, species = toupper("ANAS platYrhyncHOS"))) ) }) @@ -113,15 +118,14 @@ test_that(paste( "species accepts use of common names and return", "the same as using scientic name" ), { - # define scientific name scn <- "Anas platyrhynchos" # define correspondent vernacular name vn <- "Mallard" # get number of observations for both cases - output_anas_platyrhyncos <- get_n_obs(mica, species = scn) - output_mallard <- get_n_obs(mica, species = vn) + output_anas_platyrhyncos <- suppressMessages(get_n_obs(mica, species = scn)) + output_mallard <- suppressMessages(get_n_obs(mica, species = vn)) # same outputs expect_equal(output_anas_platyrhyncos, output_mallard) @@ -129,8 +133,10 @@ test_that(paste( test_that("if subset of species is specified, less observations are returned", { output_all_species <- get_n_obs(mica) - output_anas_platyrhyncos <- get_n_obs(mica, - species = "Anas platyrhynchos" + output_anas_platyrhyncos <- suppressMessages( + get_n_obs(mica, + species = "Anas platyrhynchos" + ) ) expect_true(sum(output_all_species$n) >= sum(output_anas_platyrhyncos$n)) @@ -170,16 +176,18 @@ test_that(paste( dplyr::pull(.data$sequenceID) %>% dplyr::n_distinct() # one sequenceID linked to two observations (different age, sex and count) - n_obs <- get_n_obs(mica, + n_obs <- suppressMessages(get_n_obs(mica, species = "Mallard", pred("deploymentID", deploy_id) - ) + )) expect_equal(n_obs$n, n_obs_via_sequence_id) }) test_that("sex filters data correctly", { sex_value <- "female" - n_obs_females <- get_n_obs(mica, species = NULL, sex = sex_value) + n_obs_females <- suppressMessages( + get_n_obs(mica, species = NULL, sex = sex_value) + ) tot_n_obs_females <- sum(n_obs_females$n) expect_equal(tot_n_obs_females, 1) expect_equal(nrow(n_obs_females), nrow(mica$data$deployments)) @@ -187,10 +195,10 @@ test_that("sex filters data correctly", { test_that("multiple sex values allowed", { sex_value <- c("female", "unknown") - n_obs_females_unknown <- get_n_obs(mica, + n_obs_females_unknown <- suppressMessages(get_n_obs(mica, species = NULL, sex = sex_value - ) + )) tot_n_obs_females_unknown <- sum(n_obs_females_unknown$n) expect_equal( tot_n_obs_females_unknown, @@ -209,7 +217,9 @@ test_that("life_stage filters data correctly", { dplyr::filter(.data$lifeStage %in% life_stage_value) %>% dplyr::distinct(.data$sequenceID) %>% nrow() - n_obs_subadult <- get_n_obs(mica, species = NULL, life_stage = life_stage_value) + n_obs_subadult <- suppressMessages( + get_n_obs(mica, species = NULL, life_stage = life_stage_value) + ) tot_n_obs_subadult <- sum(n_obs_subadult$n) expect_equal(tot_n_obs_subadult, n_obs_subadult_via_distinct) expect_equal(nrow(n_obs_subadult), nrow(mica$data$deployments)) @@ -217,7 +227,9 @@ test_that("life_stage filters data correctly", { test_that("multiple age values allowed", { life_stage_value <- c("subadult", "adult") - n_obs_subadult_adult <- get_n_obs(mica, species = NULL, life_stage = life_stage_value) + n_obs_subadult_adult <- suppressMessages( + get_n_obs(mica, species = NULL, life_stage = life_stage_value) + ) tot_n_obs_subadult_adult <- sum(n_obs_subadult_adult$n) n_obs_subadult_adult_calculate <- mica$data$observations %>% @@ -238,7 +250,9 @@ test_that(paste( ), { species_value <- "Anas platyrhynchos" sex_value <- "female" - n_obs <- get_n_obs(mica, species = species_value, sex = sex_value) + n_obs <- suppressMessages( + get_n_obs(mica, species = species_value, sex = sex_value) + ) expect_true(all(n_obs$scientificName %in% species_value)) expect_true(all(species_value %in% n_obs$scientificName)) }) @@ -255,10 +269,14 @@ test_that("Filter by date of deployments via predicates works correctly", { mica_with_obs_filtered_manually$data$observations <- mica_with_obs_filtered_manually$data$observations %>% dplyr::filter(.data$deploymentID %in% deploys_filtered) - obs_filtered_man <- get_n_obs(mica_with_obs_filtered_manually, - pred_lt(arg = "end", value = end_date)) %>% + obs_filtered_man <- suppressMessages(get_n_obs( + mica_with_obs_filtered_manually, + pred_lt(arg = "end", value = end_date) + )) %>% dplyr::arrange(deploymentID, scientificName) - obs_filtered <- get_n_obs(mica, pred_lt(arg = "end", value = end_date)) %>% + obs_filtered <- suppressMessages( + get_n_obs(mica, pred_lt(arg = "end", value = end_date)) + ) %>% dplyr::arrange(deploymentID, scientificName) expect_equal(obs_filtered, obs_filtered_man) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-get_rai.R b/tests/testthat/test-get_rai.R index 851991ae..52844f55 100644 --- a/tests/testthat/test-get_rai.R +++ b/tests/testthat/test-get_rai.R @@ -4,8 +4,10 @@ test_that("get_rai returns error if no species is specified", { }) test_that("get_rai returns the right dataframe", { - output_anas_platyrhyncos <- get_rai(mica, - species = "Anas platyrhynchos" + output_anas_platyrhyncos <- suppressMessages( + get_rai(mica, + species = "Anas platyrhynchos" + ) ) # type list @@ -66,15 +68,19 @@ test_that("get_rai returns the same if 'all' is used instead of vector with all test_that("species is case insensitive", { expect_equal( - get_rai(mica, species = "Anas platyrhynchos"), - get_rai(mica, species = toupper("Anas platyrhynchos")) + suppressMessages(get_rai(mica, species = "Anas platyrhynchos")), + suppressMessages(get_rai(mica, species = toupper("Anas platyrhynchos"))) ) }) test_that("sex filters data correctly", { sex_value <- "female" - n_obs_females <- get_n_obs(mica, species = "Mallard", sex = sex_value) - rai_females <- get_rai(mica, species = "Mallard", sex = sex_value) + n_obs_females <- suppressMessages( + get_n_obs(mica, species = "Mallard", sex = sex_value) + ) + rai_females <- suppressMessages( + get_rai(mica, species = "Mallard", sex = sex_value) + ) # same first two cols as in get_n_obs expect_equal(names(n_obs_females)[1:2], names(rai_females)[1:2]) expect_equal(nrow(n_obs_females), nrow(rai_females)) @@ -85,8 +91,12 @@ test_that("sex filters data correctly", { test_that("life_stage filters data correctly", { life_stage_value <- "subadult" - n_obs_subadult <- get_n_obs(mica, species = "Mallard", life_stage = life_stage_value) - rai_subadult <- get_rai(mica, species = "Mallard", life_stage = life_stage_value) + n_obs_subadult <- suppressMessages( + get_n_obs(mica, species = "Mallard", life_stage = life_stage_value) + ) + rai_subadult <- suppressMessages( + get_rai(mica, species = "Mallard", life_stage = life_stage_value) + ) # same first two cols as in get_n_obs expect_equal(names(n_obs_subadult)[1:2], names(rai_subadult)[1:2]) expect_equal(nrow(n_obs_subadult), nrow(rai_subadult)) diff --git a/tests/testthat/test-get_rai_individuals.R b/tests/testthat/test-get_rai_individuals.R index b6df1be4..601f5649 100644 --- a/tests/testthat/test-get_rai_individuals.R +++ b/tests/testthat/test-get_rai_individuals.R @@ -4,8 +4,10 @@ test_that("get_rai_individuals returns error if no species is specified", { }) test_that("get_rai_individuals returns the right dataframe", { - output_anas_platyrhyncos <- get_rai_individuals(mica, - species = "Anas platyrhynchos" + output_anas_platyrhyncos <- suppressMessages( + get_rai_individuals(mica, + species = "Anas platyrhynchos" + ) ) # type list @@ -66,15 +68,23 @@ test_that("get_rai_individuals returns the same if 'all' is used instead of vect test_that("species is case insensitive", { expect_equal( - get_rai_individuals(mica, species = "Anas platyrhynchos"), - get_rai_individuals(mica, species = toupper("Anas platyrhynchos")) + suppressMessages( + get_rai_individuals(mica, species = "Anas platyrhynchos") + ), + suppressMessages( + get_rai_individuals(mica, species = toupper("Anas platyrhynchos")) + ) ) }) test_that("sex filters data correctly", { sex_value <- "female" - n_obs_females <- get_n_obs(mica, species = "Mallard", sex = sex_value) - rai_females <- get_rai_individuals(mica, species = "Mallard", sex = sex_value) + n_obs_females <- suppressMessages( + get_n_obs(mica, species = "Mallard", sex = sex_value) + ) + rai_females <- suppressMessages( + get_rai_individuals(mica, species = "Mallard", sex = sex_value) + ) # same first two cols as in get_n_obs expect_equal(names(n_obs_females)[1:2], names(rai_females)[1:2]) expect_equal(nrow(n_obs_females), nrow(rai_females)) @@ -85,8 +95,12 @@ test_that("sex filters data correctly", { test_that("life_stage filters data correctly", { life_stage_value <- "subadult" - n_obs_subadult <- get_n_obs(mica, species = "Mallard", life_stage = life_stage_value) - rai_subadult <- get_rai_individuals(mica, species = "Mallard", life_stage = life_stage_value) + n_obs_subadult <- suppressMessages( + get_n_obs(mica, species = "Mallard", life_stage = life_stage_value) + ) + rai_subadult <- suppressMessages( + get_rai_individuals(mica, species = "Mallard", life_stage = life_stage_value) + ) # same first two cols as in get_n_obs expect_equal(names(n_obs_subadult)[1:2], names(rai_subadult)[1:2]) expect_equal(nrow(n_obs_subadult), nrow(rai_subadult)) diff --git a/tests/testthat/test-get_record_table.R b/tests/testthat/test-get_record_table.R index a39f725d..d6dc6adf 100644 --- a/tests/testthat/test-get_record_table.R +++ b/tests/testthat/test-get_record_table.R @@ -38,9 +38,11 @@ test_that("if not integer, minDeltaTime is set to integer (floor)", { minDeltaTime = 1000, deltaTimeComparedTo = "lastRecord" ) - record_table_dec <- get_record_table(mica, - minDeltaTime = 1000.7, - deltaTimeComparedTo = "lastRecord" + record_table_dec <- suppressMessages( + get_record_table(mica, + minDeltaTime = 1000.7, + deltaTimeComparedTo = "lastRecord" + ) ) testthat::expect_equal(record_table_int, record_table_dec) }) @@ -91,10 +93,10 @@ test_that("Higher minDeltaTime means less rows returned", { deltaTimeComparedTo = "lastRecord" ) %>% nrow() - nrow_delta_10000 <- get_record_table(mica, + nrow_delta_10000 <- suppressMessages(get_record_table(mica, minDeltaTime = 10000, deltaTimeComparedTo = "lastRecord" - ) %>% + )) %>% nrow() testthat::expect_true(nrow_delta_1000 <= nrow_delta_0) testthat::expect_true(nrow_delta_10000 <= nrow_delta_1000) @@ -133,17 +135,18 @@ test_that( # add n media, observationID and sequenceID to record table output <- output %>% dplyr::mutate(len = purrr::map_dbl(Directory, function(x) length(x))) %>% - dplyr::left_join(mica$data$observations %>% - dplyr::select( - observationID, - timestamp, - scientificName, - sequenceID - ), - by = c( - "DateTimeOriginal" = "timestamp", - "Species" = "scientificName" - ) + dplyr::left_join( + mica$data$observations %>% + dplyr::select( + observationID, + timestamp, + scientificName, + sequenceID + ), + by = c( + "DateTimeOriginal" = "timestamp", + "Species" = "scientificName" + ) ) n_media <- mica$data$media %>% @@ -184,7 +187,7 @@ test_that(paste( test_that("filtering predicates are allowed and work well", { stations <- unique( - get_record_table(mica, pred_lt("longitude", 4.0))$Station + suppressMessages(get_record_table(mica, pred_lt("longitude", 4.0)))$Station ) stations_calculate <- mica$data$deployments %>% dplyr::filter(longitude < 4.0) %>% From 46ab17a97409adf25394a57a0184233758cb0e8d Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 24 Jul 2023 14:17:36 +0200 Subject: [PATCH 21/40] Adap read function to new output check_package --- R/read_camtrap_dp.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/read_camtrap_dp.R b/R/read_camtrap_dp.R index d98bca53..aea7e58b 100644 --- a/R/read_camtrap_dp.R +++ b/R/read_camtrap_dp.R @@ -147,7 +147,7 @@ read_camtrap_dp <- function(file = NULL, } package$data <- data - package <- check_package(package, media = media) + check_package(package, media = media) package <- add_taxonomic_info(package) @@ -165,7 +165,7 @@ read_camtrap_dp <- function(file = NULL, package$data$media <- order_cols_media(package$data$media) } - package <- check_package(package, media = media) + check_package(package, media = media) # Inherit parsing issues from reading attr(package$data$observations, which = "problems") <- issues_observations From 15d971cee378a2af76aa219f38fdddbbdc9284cb Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 24 Jul 2023 14:18:05 +0200 Subject: [PATCH 22/40] Avoid returning TRUE explicitly --- R/check_package.R | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/R/check_package.R b/R/check_package.R index bcd3f66b..882d3003 100644 --- a/R/check_package.R +++ b/R/check_package.R @@ -46,11 +46,12 @@ check_package <- function(package = NULL, tables_absent <- elements[ !elements %in% names(package$data) ] - assertthat::assert_that(length(tables_absent) == 0, - msg = glue::glue( - "Can't find {tables_absent} elements in data package: {tables_absent*}", - .transformer = collapse_transformer(sep = ", ", last = " and ") - ) + assertthat::assert_that( + length(tables_absent) == 0, + msg = glue::glue( + "Can't find {tables_absent} elements in data package: {tables_absent*}", + .transformer = collapse_transformer(sep = ", ", last = " and ") + ) ) if (media) { assertthat::assert_that( @@ -65,6 +66,5 @@ check_package <- function(package = NULL, if (!is.null(package$data$media)) { assertthat::assert_that(is.data.frame(package$data$media)) } - # When all is good, return TRUE - return(TRUE) + # When all is good, nothing } From 36404cad32875481c9549429c96b9476bfc778b8 Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 24 Jul 2023 14:18:49 +0200 Subject: [PATCH 23/40] Improve documentation about returned object --- R/check_package.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/check_package.R b/R/check_package.R index 882d3003..3e78a289 100644 --- a/R/check_package.R +++ b/R/check_package.R @@ -11,7 +11,7 @@ #' @param datapkg Deprecated. Use `package` instead. #' @param media Has the `media` resource been loaded while reading the data #' package? Default: `FALSE`. -#' @return A camera trap data package. +#' @return `TRUE` or error. #' @noRd check_package <- function(package = NULL, datapkg = NULL, From ada3a0d6ab45271756d7decf34fccf9078b52e7d Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 24 Jul 2023 14:18:59 +0200 Subject: [PATCH 24/40] Run devtools::document() --- man/write_dwc.Rd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/man/write_dwc.Rd b/man/write_dwc.Rd index 4642e94e..13e8310b 100644 --- a/man/write_dwc.Rd +++ b/man/write_dwc.Rd @@ -15,13 +15,13 @@ useful for extending/adapting the Darwin Core mapping before writing with \code{\link[readr:write_delim]{readr::write_csv()}}.} } \value{ -CSV file(s) written to disk or list of data frames when -\code{directory = NULL}. +CSV and \code{meta.xml} files written to disk or a list of data +frames when \code{directory = NULL}. } \description{ Transforms data from a \href{https://tdwg.github.io/camtrap-dp/}{Camera Trap Data Package} to \href{https://dwc.tdwg.org/}{Darwin Core}. -The resulting CSV file(s) can be uploaded to an \href{https://www.gbif.org/ipt}{IPT} for publication to GBIF. -A \code{meta.xml} file is not created. +The resulting CSV files can be uploaded to an \href{https://www.gbif.org/ipt}{IPT} for publication to GBIF. +A \code{meta.xml} file is included as well. See \code{write_eml()} to create an \code{eml.xml} file. } \section{Transformation details}{ From ca26d97b9006ed4964e77ec9bec4c90c3eee34df Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 24 Jul 2023 18:00:32 +0200 Subject: [PATCH 25/40] Add/ improve messages in assertions Probably removed while merging from main? --- R/check_package.R | 9 ++++++--- tests/testthat/test-check_package.R | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/R/check_package.R b/R/check_package.R index 3e78a289..242c7986 100644 --- a/R/check_package.R +++ b/R/check_package.R @@ -33,10 +33,13 @@ check_package <- function(package = NULL, msg = "`media` must be a logical: TRUE or FALSE" ) # camera trap data package is a list - assertthat::assert_that(is.list(package)) - assertthat::assert_that(!is.data.frame(package)) + assertthat::assert_that(is.list(package), + msg = "package is not a list.") + assertthat::assert_that(!is.data.frame(package), + msg = "package is not a list.") # check existence of an element called data - assertthat::assert_that("data" %in% names(package)) + assertthat::assert_that("data" %in% names(package), + msg = "data element is missing from package") # check validity data element of package: does it contain deployments and # observations? elements <- c("deployments", "observations") diff --git a/tests/testthat/test-check_package.R b/tests/testthat/test-check_package.R index 01dedd7c..49e012ae 100644 --- a/tests/testthat/test-check_package.R +++ b/tests/testthat/test-check_package.R @@ -9,12 +9,13 @@ test_that("check_package() returns depreciation warning on datapkg argument", { test_that("check_package() returns error when package is not a list", { expect_error( check_package("not a list!"), - regexp = "package is not a list", + regexp = "package is not a list.", fixed = TRUE ) expect_error( - check_package(data.frame(letters = c("a", "b", "c"), numbers = c(pi, 2 * pi, 3 * pi))), - regexp = "package is not a list", + check_package(data.frame(letters = c("a", "b", "c"), + numbers = c(pi, 2 * pi, 3 * pi))), + regexp = "package is not a list.", fixed = TRUE ) }) From 0c748eb4bba7c21d2020be4785410ccd61a67008 Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 24 Jul 2023 18:01:22 +0200 Subject: [PATCH 26/40] Remove typo while forming the message --- R/check_package.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/check_package.R b/R/check_package.R index 242c7986..1ae7029e 100644 --- a/R/check_package.R +++ b/R/check_package.R @@ -52,7 +52,7 @@ check_package <- function(package = NULL, assertthat::assert_that( length(tables_absent) == 0, msg = glue::glue( - "Can't find {tables_absent} elements in data package: {tables_absent*}", + "Can't find {length(tables_absent)} elements in data package: {tables_absent*}", .transformer = collapse_transformer(sep = ", ", last = " and ") ) ) From 819fdce4a2a879af07ef7849f67c4c43d8dd540b Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 24 Jul 2023 18:01:48 +0200 Subject: [PATCH 27/40] Add return(TRUE) back at the end of function --- R/check_package.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/check_package.R b/R/check_package.R index 1ae7029e..aeebf8e8 100644 --- a/R/check_package.R +++ b/R/check_package.R @@ -69,5 +69,6 @@ check_package <- function(package = NULL, if (!is.null(package$data$media)) { assertthat::assert_that(is.data.frame(package$data$media)) } - # When all is good, nothing + # If no errors are encountered, TRUE is returned + return(TRUE) } From 0fbdda24d7a58fc6a12d2c7e619edfc448352087 Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 24 Jul 2023 18:02:46 +0200 Subject: [PATCH 28/40] Avoid using media element while testing missing element in data This because check_package() has been improved by adding media = FALSE by default. --- tests/testthat/test-check_package.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-check_package.R b/tests/testthat/test-check_package.R index 49e012ae..93cd1fd2 100644 --- a/tests/testthat/test-check_package.R +++ b/tests/testthat/test-check_package.R @@ -29,18 +29,18 @@ test_that("check_package() returns error on missing data", { }) test_that("check_package() returns error if not all elements are present", { - mica_no_media <- mica - mica_no_media$data$media <- NULL + mica_no_dep <- mica + mica_no_dep$data$deployments <- NULL expect_error( - check_package(mica_no_media), - regexp = "Can't find 1 elements in data package: media", + check_package(mica_no_dep, media = TRUE), + regexp = "Can't find 1 elements in data package: deployments", fixed = TRUE ) - mica_no_media_no_obs <- mica_no_media - mica_no_media_no_obs$data$observations <- NULL + mica_no_dep_no_obs <- mica_no_dep + mica_no_dep_no_obs$data$observations <- NULL expect_error( - check_package(mica_no_media_no_obs), - regexp = "Can't find 2 elements in data package: media and observations", + check_package(mica_no_dep_no_obs), + regexp = "Can't find 2 elements in data package: deployments and observations", fixed = TRUE ) }) From 353a18cd51de872eb18cabafc08c98bffda0dfc9 Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 24 Jul 2023 18:04:47 +0200 Subject: [PATCH 29/40] Add test about media flag argument --- tests/testthat/test-check_package.R | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-check_package.R b/tests/testthat/test-check_package.R index 93cd1fd2..38e01e51 100644 --- a/tests/testthat/test-check_package.R +++ b/tests/testthat/test-check_package.R @@ -45,10 +45,21 @@ test_that("check_package() returns error if not all elements are present", { ) }) +test_that( + "check_package() returns an error when media element is NULL only if media flag is TRUE", { + mica_no_media <- mica + mica_no_media$data$media <- NULL + expect_error( + check_package(mica_no_media, media = TRUE), + regexp = "Can't find 1 elements in data package: media", + fixed = TRUE + ) + expect_true(check_package(mica_no_media)) +}) + test_that("check_package() returns error if observations is not a data.frame", { mica_listed <- mica mica_listed$data$observations <- as.list(mica_listed$data$observations) - expect_error( check_package(mica_listed), regexp = "package$data$observations is not a data frame", From 366d81c33042891805c23e0b99207bb07683ccbc Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 24 Jul 2023 18:05:09 +0200 Subject: [PATCH 30/40] Improve test definition back --- tests/testthat/test-check_package.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-check_package.R b/tests/testthat/test-check_package.R index 38e01e51..207117ff 100644 --- a/tests/testthat/test-check_package.R +++ b/tests/testthat/test-check_package.R @@ -94,6 +94,6 @@ test_that("check_package() returns error if media is not a data.frame", { ) }) -test_that("check_package() returns TRUE on valid package", { +test_that("check_package() returns nothing on valid package", { expect_true(check_package(mica)) }) From 7c21229157a1759e2cb99be174a454f6710f2f43 Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 24 Jul 2023 18:05:19 +0200 Subject: [PATCH 31/40] Run devtools::document() --- man/map_dep.Rd | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/man/map_dep.Rd b/man/map_dep.Rd index f3af4cfa..c8994adc 100644 --- a/man/map_dep.Rd +++ b/man/map_dep.Rd @@ -326,6 +326,25 @@ map_dep( zero_values_icon_url = "https://img.icons8.com/ios-glyphs/30/2ECC71/futurama-fry.png" ) +# Same behavior for the icon visualizing NA values (`"n_species"` feature) +unknown_species_vs_no_obs <- mica +unknown_species_vs_no_obs$data$observations <- + unknown_species_vs_no_obs$data$observations \%>\% + # a deployment has detected only unknown species + filter(is.na(.data$scientificName) | + .data$scientificName != "Homo sapiens") \%>\% + # a deployment has no observations + filter(deploymentID != "62c200a9-0e03-4495-bcd8-032944f6f5a1") +# create new map +map_dep( + unknown_species_vs_no_obs, + feature = "n_species", + zero_values_icon_url = "https://img.icons8.com/ios-glyphs/30/2ECC71/futurama-fry.png", + zero_values_icon_size = 60, + na_values_icon_url = "https://img.icons8.com/ios-glyphs/30/E74C3C/futurama-fry.png", + na_values_icon_size = 60 +) + # Set size of the icon for zero values deployments map_dep( mica, From 3e4a077cafc1e20c093d0c3f837e7297d80ad901 Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 24 Jul 2023 21:57:11 +0200 Subject: [PATCH 32/40] Transfer deprecated datapkg arg to package --- R/get_cam_op.R | 5 ++++- R/get_custom_effort.R | 5 ++++- R/get_effort.R | 5 ++++- R/get_n_individuals.R | 5 ++++- R/get_n_obs.R | 5 ++++- R/get_n_species.R | 4 +++- R/get_rai.R | 5 ++++- R/get_record_table.R | 5 ++++- R/get_scientific_name.R | 4 ++++ R/get_species.R | 5 ++++- R/map_dep.R | 5 ++++- 11 files changed, 43 insertions(+), 10 deletions(-) diff --git a/R/get_cam_op.R b/R/get_cam_op.R index 5569d528..caecfcb5 100644 --- a/R/get_cam_op.R +++ b/R/get_cam_op.R @@ -50,7 +50,10 @@ get_cam_op <- function(package = NULL, datapkg = NULL) { # check camera trap data package check_package(package, datapkg, "get_cam_op") - + if (is.null(package) & !is.name(datapkg)) { + package <- datapkg + } + # Check that station_col is a single string assertthat::assert_that(assertthat::is.string(station_col)) # Check that station_col is one of the columns in deployments diff --git a/R/get_custom_effort.R b/R/get_custom_effort.R index 315b78ad..74c2b69c 100644 --- a/R/get_custom_effort.R +++ b/R/get_custom_effort.R @@ -117,7 +117,10 @@ get_custom_effort <- function(package = NULL, # check camera trap data package check_package(package, datapkg, "get_custom_effort") - + if (is.null(package) & !is.name(datapkg)) { + package <- datapkg + } + # get deployments deployments <- package$data$deployments diff --git a/R/get_effort.R b/R/get_effort.R index 5c6f03c0..0ef6616c 100644 --- a/R/get_effort.R +++ b/R/get_effort.R @@ -43,7 +43,10 @@ get_effort <- function(package = NULL, # check camera trap data package check_package(package, datapkg, "get_effort") - + if (is.null(package) & !is.name(datapkg)) { + package <- datapkg + } + # apply filtering package$data$deployments <- apply_filter_predicate( df = package$data$deployments, diff --git a/R/get_n_individuals.R b/R/get_n_individuals.R index 6874ae28..d982dfe1 100644 --- a/R/get_n_individuals.R +++ b/R/get_n_individuals.R @@ -68,7 +68,10 @@ get_n_individuals <- function(package = NULL, datapkg = lifecycle::deprecated()) { # check input data package check_package(package, datapkg, "get_n_individuals") - + if (is.null(package) & !is.name(datapkg)) { + package <- datapkg + } + # avoid to call variables like column names to make life easier using filter() sex_value <- sex diff --git a/R/get_n_obs.R b/R/get_n_obs.R index ddf97a15..8d3187f7 100644 --- a/R/get_n_obs.R +++ b/R/get_n_obs.R @@ -65,7 +65,10 @@ get_n_obs <- function(package = NULL, datapkg = lifecycle::deprecated()) { # check input data package check_package(package, datapkg, "get_n_obs") - + if (is.null(package) & !is.name(datapkg)) { + package <- datapkg + } + # avoid to call variables like column names to make life easier using filter() sex_value <- sex diff --git a/R/get_n_species.R b/R/get_n_species.R index 94349b13..dc7167c2 100644 --- a/R/get_n_species.R +++ b/R/get_n_species.R @@ -24,7 +24,9 @@ get_n_species <- function(package = NULL, datapkg = lifecycle::deprecated()) { # check input data package check_package(package, datapkg, "get_n_species") - + if (is.null(package) & !is.name(datapkg)) { + package <- datapkg + } # extract observations and deployments observations <- package$data$observations deployments <- package$data$deployments diff --git a/R/get_rai.R b/R/get_rai.R index 63d57e80..c8f1318a 100644 --- a/R/get_rai.R +++ b/R/get_rai.R @@ -59,7 +59,10 @@ get_rai <- function(package = NULL, datapkg = lifecycle::deprecated()) { # check camera trap data package check_package(package, datapkg, "get_rai") - + if (is.null(package) & !is.name(datapkg)) { + package <- datapkg + } + get_rai_primitive(package, ..., use = "n_obs", species = species, diff --git a/R/get_record_table.R b/R/get_record_table.R index 1a2101aa..13c06024 100644 --- a/R/get_record_table.R +++ b/R/get_record_table.R @@ -103,7 +103,10 @@ get_record_table <- function(package = NULL, datapkg = lifecycle::deprecated()) { # check data package check_package(package, datapkg, "get_record_table", media = TRUE) - + if (is.null(package) & !is.name(datapkg)) { + package <- datapkg + } + # check stationCol is a valid column name assertthat::assert_that( stationCol %in% names(package$data$deployments), diff --git a/R/get_scientific_name.R b/R/get_scientific_name.R index 29329a47..6030ad30 100644 --- a/R/get_scientific_name.R +++ b/R/get_scientific_name.R @@ -36,6 +36,10 @@ get_scientific_name <- function(package = NULL, vernacular_name, datapkg = lifecycle::deprecated()) { check_package(package, datapkg, "get_scientific_name") + if (is.null(package) & !is.name(datapkg)) { + package <- datapkg + } + all_sn_vn <- get_species(package) # get vernacular names for check diff --git a/R/get_species.R b/R/get_species.R index a48be1ef..ffc26825 100644 --- a/R/get_species.R +++ b/R/get_species.R @@ -15,7 +15,10 @@ get_species <- function(package = NULL, datapkg = lifecycle::deprecated()) { # Check camera trap data package check_package(package, datapkg, "get_species", media = FALSE) - + if (is.null(package) & !is.name(datapkg)) { + package <- datapkg + } + # Get taxonomic information from package metadata if (!"taxonomic" %in% names(package)) { return(NULL) diff --git a/R/map_dep.R b/R/map_dep.R index bf18c279..d82582e2 100644 --- a/R/map_dep.R +++ b/R/map_dep.R @@ -353,7 +353,10 @@ map_dep <- function(package = NULL, # check camera trap data package check_package(package, datapkg, "map_dep") - + if (is.null(package) & !is.name(datapkg)) { + package <- datapkg + } + # define possible feature values features <- c( "n_species", From efa45682ac80e331de633ef905bfab512c319f9e Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 24 Jul 2023 22:07:09 +0200 Subject: [PATCH 33/40] Add tests about deprecation datapkg --- tests/testthat/test-get_cam_op.R | 9 +++++++++ tests/testthat/test-get_custom_effort.R | 9 +++++++++ tests/testthat/test-get_effort.R | 9 +++++++++ tests/testthat/test-get_n_individuals.R | 9 +++++++++ tests/testthat/test-get_n_obs.R | 9 +++++++++ tests/testthat/test-get_rai.R | 9 +++++++++ tests/testthat/test-get_rai_individuals.R | 9 +++++++++ tests/testthat/test-get_record_table.R | 9 +++++++++ tests/testthat/test-get_scientific_name.R | 9 +++++++++ tests/testthat/test-map_dep.R | 9 +++++++++ 10 files changed, 90 insertions(+) diff --git a/tests/testthat/test-get_cam_op.R b/tests/testthat/test-get_cam_op.R index 902141a3..53584c24 100644 --- a/tests/testthat/test-get_cam_op.R +++ b/tests/testthat/test-get_cam_op.R @@ -166,3 +166,12 @@ test_that("filtering predicates are allowed and work well", { ) expect_equal(rownames(filtered_cam_op_matrix), "Mica Viane") }) + +test_that("Argument datapkg is deprecated: warning returned", { + expect_warning( + rlang::with_options( + lifecycle_verbosity = "warning", + get_cam_op(datapkg = mica) + ) + ) +}) diff --git a/tests/testthat/test-get_custom_effort.R b/tests/testthat/test-get_custom_effort.R index b6470b31..60c31423 100644 --- a/tests/testthat/test-get_custom_effort.R +++ b/tests/testthat/test-get_custom_effort.R @@ -180,3 +180,12 @@ test_that("check effort and unit values", { # unit value is equal to day if unit value is set to "day" expect_equal(unique(tot_effort_days$unit), "day") }) + +test_that("Argument datapkg is deprecated: warning returned", { + expect_warning( + rlang::with_options( + lifecycle_verbosity = "warning", + get_custom_effort(datapkg = mica) + ) + ) +}) \ No newline at end of file diff --git a/tests/testthat/test-get_effort.R b/tests/testthat/test-get_effort.R index c9af3cab..117e35f1 100644 --- a/tests/testthat/test-get_effort.R +++ b/tests/testthat/test-get_effort.R @@ -75,3 +75,12 @@ testthat::test_that("get_effort returns the right number of rows", { n_all_deployments ) }) + +test_that("Argument datapkg is deprecated: warning returned", { + expect_warning( + rlang::with_options( + lifecycle_verbosity = "warning", + get_effort(datapkg = mica) + ) + ) +}) \ No newline at end of file diff --git a/tests/testthat/test-get_n_individuals.R b/tests/testthat/test-get_n_individuals.R index ee12f289..d724af26 100644 --- a/tests/testthat/test-get_n_individuals.R +++ b/tests/testthat/test-get_n_individuals.R @@ -247,3 +247,12 @@ test_that("error returned if life stage or sex is not present", { expect_error(get_n_individuals(mica, life_stage = "bad")) expect_error(get_n_individuals(mica, sex = "bad")) }) + +test_that("Argument datapkg is deprecated: warning returned", { + expect_warning( + rlang::with_options( + lifecycle_verbosity = "warning", + get_n_individuals(datapkg = mica) + ) + ) +}) diff --git a/tests/testthat/test-get_n_obs.R b/tests/testthat/test-get_n_obs.R index 6629aeea..2a876320 100644 --- a/tests/testthat/test-get_n_obs.R +++ b/tests/testthat/test-get_n_obs.R @@ -280,3 +280,12 @@ test_that("Filter by date of deployments via predicates works correctly", { dplyr::arrange(deploymentID, scientificName) expect_equal(obs_filtered, obs_filtered_man) }) + +test_that("Argument datapkg is deprecated: warning returned", { + expect_warning( + rlang::with_options( + lifecycle_verbosity = "warning", + get_n_obs(datapkg = mica) + ) + ) +}) diff --git a/tests/testthat/test-get_rai.R b/tests/testthat/test-get_rai.R index 52844f55..6da186d6 100644 --- a/tests/testthat/test-get_rai.R +++ b/tests/testthat/test-get_rai.R @@ -104,3 +104,12 @@ test_that("life_stage filters data correctly", { ignore_attr = TRUE ) }) + +test_that("Argument datapkg is deprecated: warning returned", { + expect_warning( + rlang::with_options( + lifecycle_verbosity = "warning", + get_rai(datapkg = mica) + ) + ) +}) \ No newline at end of file diff --git a/tests/testthat/test-get_rai_individuals.R b/tests/testthat/test-get_rai_individuals.R index 601f5649..2fd4bc62 100644 --- a/tests/testthat/test-get_rai_individuals.R +++ b/tests/testthat/test-get_rai_individuals.R @@ -108,3 +108,12 @@ test_that("life_stage filters data correctly", { ignore_attr = TRUE ) }) + +test_that("Argument datapkg is deprecated: warning returned", { + expect_warning( + rlang::with_options( + lifecycle_verbosity = "warning", + get_rai_individuals(datapkg = mica) + ) + ) +}) \ No newline at end of file diff --git a/tests/testthat/test-get_record_table.R b/tests/testthat/test-get_record_table.R index d6dc6adf..64dcc440 100644 --- a/tests/testthat/test-get_record_table.R +++ b/tests/testthat/test-get_record_table.R @@ -194,3 +194,12 @@ test_that("filtering predicates are allowed and work well", { dplyr::pull(locationName) testthat::expect_identical(stations, stations_calculate) }) + +test_that("Argument datapkg is deprecated: warning returned", { + expect_warning( + rlang::with_options( + lifecycle_verbosity = "warning", + get_record_table(datapkg = mica) + ) + ) +}) \ No newline at end of file diff --git a/tests/testthat/test-get_scientific_name.R b/tests/testthat/test-get_scientific_name.R index 43ed331b..8513eca8 100644 --- a/tests/testthat/test-get_scientific_name.R +++ b/tests/testthat/test-get_scientific_name.R @@ -18,3 +18,12 @@ test_that("Functions works case insensitively", { sc_names <- get_scientific_name(mica, c("beeCH MArten")) expect_equal(sc_names, c("Martes foina")) }) + +test_that("Argument datapkg is deprecated: warning returned", { + expect_warning( + rlang::with_options( + lifecycle_verbosity = "warning", + get_scientific_name(datapkg = mica, vernacular_name = "beech marten") + ) + ) +}) \ No newline at end of file diff --git a/tests/testthat/test-map_dep.R b/tests/testthat/test-map_dep.R index ebc06d0e..39746413 100644 --- a/tests/testthat/test-map_dep.R +++ b/tests/testthat/test-map_dep.R @@ -226,3 +226,12 @@ test_that("map_dep() returns a leaflet", { expect_no_error(map_dep(mica, feature = "n_species")) expect_no_message(map_dep(mica, feature = "n_species")) }) + +test_that("Argument datapkg is deprecated: warning returned", { + expect_warning( + rlang::with_options( + lifecycle_verbosity = "warning", + map_dep(datapkg = mica, feature = "n_obs") + ) + ) +}) From 31b35e945d9c58cbcc1e98d0e5d4801f323d2da2 Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Tue, 25 Jul 2023 10:07:22 +0200 Subject: [PATCH 34/40] Add deprecation to datapkg where forgotten --- R/get_cam_op.R | 2 +- R/get_custom_effort.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/get_cam_op.R b/R/get_cam_op.R index caecfcb5..d366c1a1 100644 --- a/R/get_cam_op.R +++ b/R/get_cam_op.R @@ -47,7 +47,7 @@ get_cam_op <- function(package = NULL, ..., station_col = "locationName", use_prefix = FALSE, - datapkg = NULL) { + datapkg = lifecycle::deprecated()) { # check camera trap data package check_package(package, datapkg, "get_cam_op") if (is.null(package) & !is.name(datapkg)) { diff --git a/R/get_custom_effort.R b/R/get_custom_effort.R index 74c2b69c..8c52a40c 100644 --- a/R/get_custom_effort.R +++ b/R/get_custom_effort.R @@ -91,7 +91,7 @@ get_custom_effort <- function(package = NULL, end = NULL, group_by = NULL, unit = "hour", - datapkg = NULL) { + datapkg = lifecycle::deprecated()) { # define possible unit values units <- c("hour", "day") From a4d6a1066a49415ed1c3015f9d9fda984d1a0ba8 Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Tue, 25 Jul 2023 10:11:54 +0200 Subject: [PATCH 35/40] Apply devtools::document() --- man/get_cam_op.Rd | 2 +- man/get_custom_effort.Rd | 2 +- tests/testthat/test-get_species.R | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/man/get_cam_op.Rd b/man/get_cam_op.Rd index 86d8dfe3..83c57185 100644 --- a/man/get_cam_op.Rd +++ b/man/get_cam_op.Rd @@ -9,7 +9,7 @@ get_cam_op( ..., station_col = "locationName", use_prefix = FALSE, - datapkg = NULL + datapkg = lifecycle::deprecated() ) } \arguments{ diff --git a/man/get_custom_effort.Rd b/man/get_custom_effort.Rd index 47bade10..2dc4e92a 100644 --- a/man/get_custom_effort.Rd +++ b/man/get_custom_effort.Rd @@ -11,7 +11,7 @@ get_custom_effort( end = NULL, group_by = NULL, unit = "hour", - datapkg = NULL + datapkg = lifecycle::deprecated() ) } \arguments{ diff --git a/tests/testthat/test-get_species.R b/tests/testthat/test-get_species.R index bdadf78e..e03c8847 100644 --- a/tests/testthat/test-get_species.R +++ b/tests/testthat/test-get_species.R @@ -77,6 +77,20 @@ test_that("Argument datapkg is deprecated: warning returned", { rlang::with_options( lifecycle_verbosity = "warning", get_species(datapkg = mica) - ) + ), + paste0("\033[38;5;232mThe `datapkg` argument of `get_species()` is ", + "deprecated as of camtraptor 0.16.0.\n\033[36mℹ\033[38;5;232m Please", + " use the `package` argument instead.\n\033[36mℹ\033[38;5;232m The", + " deprecated feature was likely used in the ", + "\033[34mcamtraptor\033[38;5;232m package.\n ", + "Please report the issue at \033[3m\033[34m<\033]8;;", + "https://github.com/inbo/camtraptor/issues\a", + "https://github.com/inbo/camtraptor/issues\033]8;;", + "\a>\033[38;5;232m\033[23m.\n\033[90mThis warning is displayed ", + "once every 8 hours.\033[38;5;232m\n\033[90mCall ", + "`lifecycle::last_lifecycle_warnings()` to see where this warning ", + "was generated.\033[38;5;232m\033[39m" + ), + fixed = TRUE ) }) From 1a4363984fe23207e451ea3a8b6f636b491c8cab Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Tue, 25 Jul 2023 10:14:23 +0200 Subject: [PATCH 36/40] Support deprecation in get_rai_individuals as well --- R/get_rai.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/get_rai.R b/R/get_rai.R index c8f1318a..0a6de37e 100644 --- a/R/get_rai.R +++ b/R/get_rai.R @@ -139,6 +139,10 @@ get_rai_individuals <- function(package = NULL, datapkg = lifecycle::deprecated()) { # check camera trap data package check_package(package, datapkg, "get_rai_individuals") + if (is.null(package) & !is.name(datapkg)) { + package <- datapkg + } + get_rai_primitive(package, ..., use = "n_individuals", species = species, From 5439c232493e8261cf93bacdf4d9a6774e5c1c2a Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Tue, 25 Jul 2023 10:42:10 +0200 Subject: [PATCH 37/40] Use dplyr::func_name() syntax in test --- tests/testthat/test-get_n_species.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-get_n_species.R b/tests/testthat/test-get_n_species.R index fd534791..9d15878e 100644 --- a/tests/testthat/test-get_n_species.R +++ b/tests/testthat/test-get_n_species.R @@ -27,7 +27,7 @@ test_that("get_n_species returns 0 for obs without recognized species", { unknown_species$data$observations <- unknown_species$data$observations %>% # a deployment has detected only unknown species - filter(is.na(.data$scientificName) | + dplyr::filter(is.na(.data$scientificName) | .data$scientificName != "Homo sapiens") n_species <- get_n_species(package = unknown_species) expect_equal(n_species[n_species$n == 0,]$n, 0) From 5155d10ff6ad41c7b14e8271cc8df4ff012573fa Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Tue, 25 Jul 2023 10:42:44 +0200 Subject: [PATCH 38/40] Add suppressMessages() to better read output tests --- tests/testthat/test-get_n_species.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-get_n_species.R b/tests/testthat/test-get_n_species.R index 9d15878e..9f7edc9b 100644 --- a/tests/testthat/test-get_n_species.R +++ b/tests/testthat/test-get_n_species.R @@ -41,7 +41,7 @@ test_that("get_n_species returns NA for deployments without observations", { dep_no_obs <- "29b7d356-4bb4-4ec4-b792-2af5cc32efa8" obs <- obs[obs$deploymentID != dep_no_obs,] no_obs$data$observations <- obs - n_species <- get_n_species(package = no_obs) + n_species <- suppressMessages(get_n_species(package = no_obs)) expect_true(is.na(n_species[n_species$deploymentID == dep_no_obs,]$n)) }) From db8e01a4b7efc14fa93f4ac0bc096a61ce219633 Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Tue, 25 Jul 2023 10:43:43 +0200 Subject: [PATCH 39/40] Add suppressMessages in test for read_ function --- tests/testthat/test-read_camtrap_dp.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index 60046226..48cd60c8 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -21,12 +21,12 @@ test_that("file can be an URL", { test_that("only DP versions 1.0-rc.1 and dp 0.1.6 are supported", { expect_error( - read_camtrap_dp("https://raw.githubusercontent.com/tdwg/camtrap-dp/bb046c85a55bef2ced709357c0047f0136df8326/example/datapackage.json"), + suppressMessages(read_camtrap_dp("https://raw.githubusercontent.com/tdwg/camtrap-dp/bb046c85a55bef2ced709357c0047f0136df8326/example/datapackage.json")), "Version https://raw.githubusercontent.com/tdwg/camtrap-dp/0.5/camtrap-dp-profile.json is not supported. Supported versions: 0.1.6 and 1.0-rc.1." ) expect_error( - read_camtrap_dp("https://raw.githubusercontent.com/tdwg/dwc-for-biologging/403f57db105982dc05b70f3cf66fd2b5591798db/derived/camtrap-dp/data/raw/datapackage.json"), + suppressMessages(read_camtrap_dp("https://raw.githubusercontent.com/tdwg/dwc-for-biologging/403f57db105982dc05b70f3cf66fd2b5591798db/derived/camtrap-dp/data/raw/datapackage.json")), "Version tabular-data-package is not supported. Supported versions: 0.1.6 and 1.0-rc.1." ) }) From a51a3965b1d748d7bf8f0020c0be7fe47e1e067f Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Tue, 25 Jul 2023 12:38:23 +0200 Subject: [PATCH 40/40] Add tests for deprecated arg datapkg --- tests/testthat/test-get_cam_op.R | 4 +++- tests/testthat/test-get_custom_effort.R | 6 ++++-- tests/testthat/test-get_effort.R | 4 +++- tests/testthat/test-get_n_individuals.R | 4 +++- tests/testthat/test-get_n_obs.R | 4 +++- tests/testthat/test-get_n_species.R | 4 +++- tests/testthat/test-get_rai.R | 4 +++- tests/testthat/test-get_rai_individuals.R | 6 ++++-- tests/testthat/test-get_record_table.R | 6 ++++-- tests/testthat/test-get_scientific_name.R | 6 ++++-- tests/testthat/test-get_species.R | 14 +------------- tests/testthat/test-map_dep.R | 4 +++- 12 files changed, 38 insertions(+), 28 deletions(-) diff --git a/tests/testthat/test-get_cam_op.R b/tests/testthat/test-get_cam_op.R index 53584c24..e5726572 100644 --- a/tests/testthat/test-get_cam_op.R +++ b/tests/testthat/test-get_cam_op.R @@ -172,6 +172,8 @@ test_that("Argument datapkg is deprecated: warning returned", { rlang::with_options( lifecycle_verbosity = "warning", get_cam_op(datapkg = mica) - ) + ), + regexp = "The `datapkg` argument of `get_cam_op()` is deprecated as of camtraptor 0.16.0.", + fixed = TRUE ) }) diff --git a/tests/testthat/test-get_custom_effort.R b/tests/testthat/test-get_custom_effort.R index 60c31423..1efb2d05 100644 --- a/tests/testthat/test-get_custom_effort.R +++ b/tests/testthat/test-get_custom_effort.R @@ -186,6 +186,8 @@ test_that("Argument datapkg is deprecated: warning returned", { rlang::with_options( lifecycle_verbosity = "warning", get_custom_effort(datapkg = mica) - ) + ), + regexp = "The `datapkg` argument of `get_custom_effort()` is deprecated as of camtraptor 0.16.0.", + fixed = TRUE ) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-get_effort.R b/tests/testthat/test-get_effort.R index 117e35f1..1df1a113 100644 --- a/tests/testthat/test-get_effort.R +++ b/tests/testthat/test-get_effort.R @@ -81,6 +81,8 @@ test_that("Argument datapkg is deprecated: warning returned", { rlang::with_options( lifecycle_verbosity = "warning", get_effort(datapkg = mica) - ) + ), + regexp = "The `datapkg` argument of `get_effort()` is deprecated as of camtraptor 0.16.0.", + fixed = TRUE ) }) \ No newline at end of file diff --git a/tests/testthat/test-get_n_individuals.R b/tests/testthat/test-get_n_individuals.R index d724af26..c2ff521e 100644 --- a/tests/testthat/test-get_n_individuals.R +++ b/tests/testthat/test-get_n_individuals.R @@ -253,6 +253,8 @@ test_that("Argument datapkg is deprecated: warning returned", { rlang::with_options( lifecycle_verbosity = "warning", get_n_individuals(datapkg = mica) - ) + ), + regexp = "The `datapkg` argument of `get_n_individuals()` is deprecated as of camtraptor 0.16.0.", + fixed = TRUE ) }) diff --git a/tests/testthat/test-get_n_obs.R b/tests/testthat/test-get_n_obs.R index 2a876320..0b4befd3 100644 --- a/tests/testthat/test-get_n_obs.R +++ b/tests/testthat/test-get_n_obs.R @@ -286,6 +286,8 @@ test_that("Argument datapkg is deprecated: warning returned", { rlang::with_options( lifecycle_verbosity = "warning", get_n_obs(datapkg = mica) - ) + ), + regexp = "The `datapkg` argument of `get_n_obs()` is deprecated as of camtraptor 0.16.0.", + fixed = TRUE ) }) diff --git a/tests/testthat/test-get_n_species.R b/tests/testthat/test-get_n_species.R index 9f7edc9b..19c27ef3 100644 --- a/tests/testthat/test-get_n_species.R +++ b/tests/testthat/test-get_n_species.R @@ -50,6 +50,8 @@ test_that("Argument datapkg is deprecated: warning returned", { rlang::with_options( lifecycle_verbosity = "warning", get_n_species(datapkg = mica) - ) + ), + regexp = "The `datapkg` argument of `get_n_species()` is deprecated as of camtraptor 0.16.0.", + fixed = TRUE ) }) diff --git a/tests/testthat/test-get_rai.R b/tests/testthat/test-get_rai.R index 6da186d6..dd3056df 100644 --- a/tests/testthat/test-get_rai.R +++ b/tests/testthat/test-get_rai.R @@ -110,6 +110,8 @@ test_that("Argument datapkg is deprecated: warning returned", { rlang::with_options( lifecycle_verbosity = "warning", get_rai(datapkg = mica) - ) + ), + regexp = "The `datapkg` argument of `get_rai()` is deprecated as of camtraptor 0.16.0.", + fixed = TRUE ) }) \ No newline at end of file diff --git a/tests/testthat/test-get_rai_individuals.R b/tests/testthat/test-get_rai_individuals.R index 2fd4bc62..0d59c2f8 100644 --- a/tests/testthat/test-get_rai_individuals.R +++ b/tests/testthat/test-get_rai_individuals.R @@ -114,6 +114,8 @@ test_that("Argument datapkg is deprecated: warning returned", { rlang::with_options( lifecycle_verbosity = "warning", get_rai_individuals(datapkg = mica) - ) + ), + regexp = "The `datapkg` argument of `get_rai_individuals()` is deprecated as of camtraptor 0.16.0.", + fixed = TRUE ) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-get_record_table.R b/tests/testthat/test-get_record_table.R index 64dcc440..79772aa7 100644 --- a/tests/testthat/test-get_record_table.R +++ b/tests/testthat/test-get_record_table.R @@ -200,6 +200,8 @@ test_that("Argument datapkg is deprecated: warning returned", { rlang::with_options( lifecycle_verbosity = "warning", get_record_table(datapkg = mica) - ) + ), + regexp = "The `datapkg` argument of `get_record_table()` is deprecated as of camtraptor 0.16.0.", + fixed = TRUE ) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-get_scientific_name.R b/tests/testthat/test-get_scientific_name.R index 8513eca8..415ad934 100644 --- a/tests/testthat/test-get_scientific_name.R +++ b/tests/testthat/test-get_scientific_name.R @@ -24,6 +24,8 @@ test_that("Argument datapkg is deprecated: warning returned", { rlang::with_options( lifecycle_verbosity = "warning", get_scientific_name(datapkg = mica, vernacular_name = "beech marten") - ) + ), + regexp = "The `datapkg` argument of `get_scientific_name()` is deprecated as of camtraptor 0.16.0.", + fixed = TRUE ) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-get_species.R b/tests/testthat/test-get_species.R index e03c8847..fcfb0408 100644 --- a/tests/testthat/test-get_species.R +++ b/tests/testthat/test-get_species.R @@ -78,19 +78,7 @@ test_that("Argument datapkg is deprecated: warning returned", { lifecycle_verbosity = "warning", get_species(datapkg = mica) ), - paste0("\033[38;5;232mThe `datapkg` argument of `get_species()` is ", - "deprecated as of camtraptor 0.16.0.\n\033[36mℹ\033[38;5;232m Please", - " use the `package` argument instead.\n\033[36mℹ\033[38;5;232m The", - " deprecated feature was likely used in the ", - "\033[34mcamtraptor\033[38;5;232m package.\n ", - "Please report the issue at \033[3m\033[34m<\033]8;;", - "https://github.com/inbo/camtraptor/issues\a", - "https://github.com/inbo/camtraptor/issues\033]8;;", - "\a>\033[38;5;232m\033[23m.\n\033[90mThis warning is displayed ", - "once every 8 hours.\033[38;5;232m\n\033[90mCall ", - "`lifecycle::last_lifecycle_warnings()` to see where this warning ", - "was generated.\033[38;5;232m\033[39m" - ), + regexp = "The `datapkg` argument of `get_species()` is deprecated as of camtraptor 0.16.0.", fixed = TRUE ) }) diff --git a/tests/testthat/test-map_dep.R b/tests/testthat/test-map_dep.R index 39746413..f882984e 100644 --- a/tests/testthat/test-map_dep.R +++ b/tests/testthat/test-map_dep.R @@ -232,6 +232,8 @@ test_that("Argument datapkg is deprecated: warning returned", { rlang::with_options( lifecycle_verbosity = "warning", map_dep(datapkg = mica, feature = "n_obs") - ) + ), + regexp = "The `datapkg` argument of `map_dep()` is deprecated as of camtraptor 0.16.0.", + fixed = TRUE ) })