From 9e231ef3925c3cdc1ccc656f8a6ef44456f88f05 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:16:11 +0100 Subject: [PATCH 01/39] change supported version to v1.0 only --- R/zzz.R | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index cb886e00..51b3686f 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -371,7 +371,7 @@ mutate_when_missing <- function(.data,...){ #' #' This help function adds taxonomic information in `taxonomic` element of #' metadata to `observations`. Notice that higher classification, i.e. new -#' fields in v1.0-rc.1, are removed. +#' fields in v1.0, are removed. #' #' @param package Camera trap data package. #' @return Camera trap data package with taxonomic related cols added to @@ -437,13 +437,13 @@ add_speed_radius_angle <- function(obs){ #' @param media If `TRUE` (default), read media records into memory. If `FALSE`, #' ignore media file to speed up reading larger Camtrap DP packages. #' @noRd -convert_to_0.1.6 <- function(package, from = "1.0-rc.1", media = TRUE){ +convert_to_0.1.6 <- function(package, from = "1.0", media = TRUE){ if (from == "0.1.6") { message(glue::glue("package's version: {from}. No conversion needed.")) return(package) } # check version - supported_versions <- c("1.0-rc.1") + supported_versions <- c("1.0") assertthat::assert_that( from %in% supported_versions, msg = paste0( @@ -464,7 +464,7 @@ convert_to_0.1.6 <- function(package, from = "1.0-rc.1", media = TRUE){ message( writeLines( c( - "The dataset uses Camtrap DP version 1.0-rc.1, it has been converted to 0.1.6.", + "The dataset uses Camtrap DP version 1.0, it has been converted to 0.1.6.", "See https://inbo.github.io/camtraptor/#camtrap-dp for details." ) ) @@ -485,7 +485,7 @@ convert_to_0.1.6 <- function(package, from = "1.0-rc.1", media = TRUE){ #' Convert metadata to Camtrap DP version 0.1.6 #' -#' Convert metadata of a Camtrap DP from version 1.0-rc.1 to 0.1.6 to avoid +#' Convert metadata of a Camtrap DP from version 1.0 to 0.1.6 to avoid #' breaking changes #' #' @param package Camera trap data package object. @@ -493,7 +493,7 @@ convert_to_0.1.6 <- function(package, from = "1.0-rc.1", media = TRUE){ #' @return Camera trap data package object with converted `metadata`. #' @noRd #' @importFrom dplyr %>% .data -convert_metadata_to_0.1.6 <- function(package, from = "1.0-rc.1"){ +convert_metadata_to_0.1.6 <- function(package, from = "1.0"){ authors <- purrr::map_df(package$contributors, unlist) if ("role" %in% names(authors)) { deprecated_roles <- c("author", "maintainer") @@ -542,7 +542,7 @@ convert_metadata_to_0.1.6 <- function(package, from = "1.0-rc.1"){ #' Convert deployments to Camtrap DP version 0.1.6 #' -#' Convert deployments of a Camtrap DP from version 1.0-rc.1 to 0.1.6 to avoid +#' Convert deployments of a Camtrap DP from version 1.0 to 0.1.6 to avoid #' breaking changes #' #' @param package Camera trap data package object. @@ -550,7 +550,7 @@ convert_metadata_to_0.1.6 <- function(package, from = "1.0-rc.1"){ #' @return Camera trap data package object with converted `deployments`. #' @noRd #' @importFrom dplyr %>% .data -convert_deployments_to_0.1.6 <- function(package, from = "1.0-rc.1") { +convert_deployments_to_0.1.6 <- function(package, from = "1.0") { # check deployments slot is present assertthat::assert_that( @@ -654,7 +654,7 @@ convert_deployments_to_0.1.6 <- function(package, from = "1.0-rc.1") { #' Convert media to Camtrap DP version 0.1.6 #' -#' Convert media of a Camtrap DP from version 1.0-rc.1 to 0.1.6 to avoid +#' Convert media of a Camtrap DP from version 1.0 to 0.1.6 to avoid #' breaking changes. Notice that this function `MUST` be run before #' `convert_observations_to_0.1.6()`. #' @@ -663,7 +663,7 @@ convert_deployments_to_0.1.6 <- function(package, from = "1.0-rc.1") { #' @return Camera trap data package object with converted `media`. #' @noRd #' @importFrom dplyr %>% .data -convert_media_to_0.1.6 <- function(package, from = "1.0-rc.1") { +convert_media_to_0.1.6 <- function(package, from = "1.0") { # check media slot is present assertthat::assert_that( @@ -728,7 +728,7 @@ convert_media_to_0.1.6 <- function(package, from = "1.0-rc.1") { #' Convert observations to Camtrap DP version 0.1.6 #' -#' Convert observations of a Camtrap DP from version 1.0-rc.1 to 0.1.6 to avoid +#' Convert observations of a Camtrap DP from version 1.0 to 0.1.6 to avoid #' breaking changes #' #' @param package Camera trap data package object. @@ -736,7 +736,7 @@ convert_media_to_0.1.6 <- function(package, from = "1.0-rc.1") { #' @return Camera trap data package object with converted `observations`. #' @noRd #' @importFrom dplyr %>% .data -convert_observations_to_0.1.6 <- function(package, from = "1.0-rc.1") { +convert_observations_to_0.1.6 <- function(package, from = "1.0") { # check observations slot is present assertthat::assert_that( From 22cc1b335dbf4c1ccbbc4cb5fc9d7ba8b86c7385 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 13:46:54 +0100 Subject: [PATCH 02/39] refer to v1 camtrap-dp example instead of old rc --- tests/testthat/test-read_camtrap_dp.R | 64 ++++++++++++++++++--------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index 48cd60c8..e4a7c384 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -1,3 +1,12 @@ +## read camera trap data package from v1.0-rc1 +path_to_json_v1 <- "https://raw.githubusercontent.com/tdwg/camtrap-dp/02ce57229209dd65249113a193dbad7c84b8d5da/example/datapackage.json" +dp_v1_rc1_with_media <- suppressMessages( + read_camtrap_dp(path_to_json_v1) +) +dp_v1_rc1_without_media <- suppressMessages( + read_camtrap_dp(path_to_json_v1, media = FALSE) +) + test_that("file argument is checked properly", { expect_error(read_camtrap_dp("aaa")) expect_error(read_camtrap_dp(1)) @@ -31,15 +40,6 @@ test_that("only DP versions 1.0-rc.1 and dp 0.1.6 are supported", { ) }) -## read camera trap data package from v1.0-rc1 -path_to_json_v1rc1 <- "https://raw.githubusercontent.com/tdwg/camtrap-dp/1.0-rc.1/example/datapackage.json" -dp_v1_rc1_with_media <- suppressMessages( - read_camtrap_dp(path_to_json_v1rc1) -) -dp_v1_rc1_without_media <- suppressMessages( - read_camtrap_dp(path_to_json_v1rc1, media = FALSE) -) - test_that("test warnings while reading files with parsing issues", { local_edition(2) camtrap_dp_file_with_issues <- system.file( @@ -48,10 +48,10 @@ test_that("test warnings while reading files with parsing issues", { package = "camtraptor" ) w <- capture_warnings( - camtraptor::read_camtrap_dp(file = camtrap_dp_file_with_issues) + dp_issues <- camtraptor::read_camtrap_dp(file = camtrap_dp_file_with_issues) ) # warning on deployments - expect_equal( + expect_identical( w[2], # w[1] is returned by readr via frictionless paste0( "One or more parsing issues occurred while reading `deployments`. ", @@ -59,8 +59,14 @@ test_that("test warnings while reading files with parsing issues", { "`readr::problems()`." ) ) + problems_deploys <- readr::problems(dp_issues$data$deployments) + expect_identical(nrow(problems_deploys), 2L) + expect_identical(problems_deploys$row, c(1L,2L)) + expect_identical(problems_deploys$col, c(7L,7L)) + expect_identical(problems_deploys$expected, rep("date like %Y-%m-%dT%H:%M:%S%z", 2)) + # warning on observations - expect_equal( + expect_identical( w[4], # w[3] is returned by readr via frictionless paste0( "One or more parsing issues occurred while reading `observations`. ", @@ -68,8 +74,14 @@ test_that("test warnings while reading files with parsing issues", { "`readr::problems()`." ) ) + problems_obs <- readr::problems(dp_issues$data$observations) + expect_identical(nrow(problems_obs), 2L) + expect_identical(problems_obs$row, c(1L,2L)) + expect_identical(problems_obs$col, c(5L,5L)) + expect_identical(problems_obs$expected, rep("date like %Y-%m-%dT%H:%M:%S%z", 2)) + # warning on media - expect_equal( + expect_identical( w[6], # w[5] is returned by readr via frictionless paste0( "One or more parsing issues occurred while reading `media`. ", @@ -77,6 +89,11 @@ test_that("test warnings while reading files with parsing issues", { "`readr::problems()`." ) ) + problems_media <- readr::problems(dp_issues$data$media) + expect_identical(nrow(problems_media), 1L) + expect_identical(problems_media$row, 2L) + expect_identical(problems_media$col, 5L) + expect_identical(problems_media$expected, "date like %Y-%m-%dT%H:%M:%S%z") }) test_that("media is checked properly", { @@ -97,12 +114,13 @@ test_that("output is a list", { file = dp_path, media = FALSE )) + expect_true(is.list(dp_without_media)) - expect_equal(class(dp_without_media), "list") + expect_type(dp_without_media, "list") expect_true(is.list(dp_v1_rc1_with_media)) - expect_equal(class(dp_v1_rc1_with_media), "list") + expect_type(dp_v1_rc1_with_media, "list") expect_true(is.list(dp_v1_rc1_without_media)) - expect_equal(class(dp_v1_rc1_without_media), "list") + expect_type(dp_v1_rc1_without_media, "list") }) test_that("output data slot is a list of length 3", { @@ -113,12 +131,13 @@ test_that("output data slot is a list of length 3", { file = dp_path, media = FALSE )) + expect_true("data" %in% names(dp_without_media)) - expect_equal(length(dp_without_media$data), 3) + expect_length(dp_without_media$data, 3) expect_true("data" %in% names(dp_v1_rc1_with_media)) - expect_equal(length(dp_v1_rc1_with_media$data), 3) + expect_length(dp_v1_rc1_with_media$data, 3) expect_true("data" %in% names(dp_v1_rc1_without_media)) - expect_equal(length(dp_v1_rc1_without_media$data), 3) + expect_length(dp_v1_rc1_without_media$data, 3) }) test_that("media arg influences only slot media", { @@ -334,7 +353,7 @@ test_that( "read deployments v1.0-rc1: baitUse is a factor, not a boolean", { expect_s3_class(dp_v1_rc1_with_media$data$deployments$baitUse, "factor") baitUse_levels <- c("none", "scent", "food", "visual", "acoustic", "other") - expect_equal( + expect_identical( levels(dp_v1_rc1_with_media$data$deployments$baitUse), baitUse_levels ) # boolean NA becomes a factor NA @@ -379,11 +398,12 @@ test_that( file = dp_path, media = FALSE )) + cols_deployments_dp_v1_rc1 <- dp_v1_rc1_without_media$data$deployments %>% names() cols_deployments_dp_v0_1_6 <- dp_without_media$data$deployments %>% names() - expect_equal(cols_deployments_dp_v0_1_6, cols_deployments_dp_v1_rc1) + expect_identical(cols_deployments_dp_v0_1_6, cols_deployments_dp_v1_rc1) } ) @@ -573,6 +593,6 @@ test_that( names() cols_media_dp_v0_1_6 <- dp_with_media$data$media %>% names() - expect_equal(cols_media_dp_v1_rc1, cols_media_dp_v0_1_6) + expect_identical(cols_media_dp_v1_rc1, cols_media_dp_v0_1_6) } ) From 1261a5c1ca28787657471baa77dbbecaf670693b Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 13:51:52 +0100 Subject: [PATCH 03/39] use release instead of commit --- tests/testthat/test-read_camtrap_dp.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index e4a7c384..fb4647de 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -1,5 +1,5 @@ ## read camera trap data package from v1.0-rc1 -path_to_json_v1 <- "https://raw.githubusercontent.com/tdwg/camtrap-dp/02ce57229209dd65249113a193dbad7c84b8d5da/example/datapackage.json" +path_to_json_v1 <- "https://raw.githubusercontent.com/tdwg/camtrap-dp/1.0/example/datapackage.json" dp_v1_rc1_with_media <- suppressMessages( read_camtrap_dp(path_to_json_v1) ) From 03cfcbb6a261e40153bb87f9cc283adfce778997 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 13:52:11 +0100 Subject: [PATCH 04/39] check for supporting v1.0 not rc.1 --- R/read_camtrap_dp.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/read_camtrap_dp.R b/R/read_camtrap_dp.R index aea7e58b..834c0245 100644 --- a/R/read_camtrap_dp.R +++ b/R/read_camtrap_dp.R @@ -80,12 +80,12 @@ read_camtrap_dp <- function(file = NULL, package <- frictionless::read_package(file) # supported versions - supported_versions <- c("0.1.6", "1.0-rc.1") + supported_versions <- c("0.1.6", "1.0") # get package version profile <- package$profile - if (profile == "https://raw.githubusercontent.com/tdwg/camtrap-dp/1.0-rc.1/camtrap-dp-profile.json") { - version <- "1.0-rc.1" + if (profile == "https://raw.githubusercontent.com/tdwg/camtrap-dp/1.0/camtrap-dp-profile.json") { + version <- "1.0" } else { if (profile == "https://raw.githubusercontent.com/tdwg/camtrap-dp/0.1.6/camtrap-dp-profile.json") { version <- "0.1.6" @@ -152,7 +152,7 @@ read_camtrap_dp <- function(file = NULL, package <- add_taxonomic_info(package) # convert to 0.1.6 - if (version == "1.0-rc.1") { + if (version == "1.0") { package <- convert_to_0.1.6(package, version, media = media) } From a3710b00dcf4054b15dcf96181eb1c2b2f5befa4 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 13:54:36 +0100 Subject: [PATCH 05/39] no longer use taxonID for join as per camtrap-dp v1.0 --- R/zzz.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/zzz.R b/R/zzz.R index 51b3686f..e717c003 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -397,7 +397,7 @@ add_taxonomic_info <- function(package) { dplyr::left_join( package$data$observations, taxon_infos, - by = c("taxonID", "scientificName") + by = c("scientificName") ) package$data$observations <- observations } From 1c4b612b6800624ad92a36ddccbce7a735a4fdfb Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 13:54:51 +0100 Subject: [PATCH 06/39] fail earlier on missing scientificName, no longer use taxonID --- R/zzz.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index e717c003..328aefa5 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -384,9 +384,8 @@ add_taxonomic_info <- function(package) { # classification) taxon_infos <- dplyr::select( taxon_infos, - dplyr::any_of(c("taxonID", - "taxonIDReference", - "scientificName", + dplyr::all_of("scientificName"), + dplyr::any_of(c("taxonIDReference", "taxonRank")), dplyr::starts_with("vernacularNames") ) From 08809e4b38348aaac1471453d661b5177ae2cd83 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 13:58:42 +0100 Subject: [PATCH 07/39] update to test for v1.0 `datapackage.json` --- tests/testthat/test-read_camtrap_dp.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index fb4647de..914292e5 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -16,7 +16,7 @@ test_that("file can be an URL", { # camtraptor is trailing camtrap-dp, refer to specific commit to keep using old version # dp_path <- "https://raw.githubusercontent.com/tdwg/camtrap-dp/main/example/datapackage.json" dp_path <- - "https://raw.githubusercontent.com/tdwg/camtrap-dp/81379eadfafee3398a4b498c1141e617c5982f4a/example/datapackage.json" + "https://raw.githubusercontent.com/tdwg/camtrap-dp/1.0/example/datapackage.json" dp <- suppressMessages(read_camtrap_dp( file = dp_path, media = FALSE From d75885a18fd2f81b3cf99d8da87f03584f1c27ba Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 13:58:54 +0100 Subject: [PATCH 08/39] set error expectation to v1.0 --- tests/testthat/test-read_camtrap_dp.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index 914292e5..f9ad9fb3 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -28,15 +28,17 @@ test_that("file can be an URL", { class(dp$data$observations))) }) -test_that("only DP versions 1.0-rc.1 and dp 0.1.6 are supported", { +test_that("only DP versions 1.0 and dp 0.1.6 are supported", { expect_error( 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." + "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.", + fixed = TRUE ) expect_error( 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." + "Version tabular-data-package is not supported. Supported versions: 0.1.6 and 1.0", + fixed = TRUE ) }) From bbcb3fda8fd5ba9d9af4edfd8c563037be2dbe11 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:13:45 +0100 Subject: [PATCH 09/39] Downconvert taxonID to NA Co-Authored-By: Peter Desmet --- R/zzz.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/zzz.R b/R/zzz.R index 328aefa5..92e1075b 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -823,6 +823,10 @@ convert_observations_to_0.1.6 <- function(package, from = "1.0") { } # remove bounding box related cols if present observations <- observations %>% dplyr::select(-dplyr::starts_with("bbox")) + # add taxonID if missing + if(!"taxonID" %in% colnames(observations)){ + observations <- observations %>% dplyr::mutate(taxonID = NA_integer_) + } package$data$observations <- observations return(package) From 5fda125ee5e27a914c896be9d7aaea8d9bc06969 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:14:50 +0100 Subject: [PATCH 10/39] `dp_v1` instead of `dp_v1_rc1` --- tests/testthat/test-read_camtrap_dp.R | 186 +++++++++++++------------- 1 file changed, 93 insertions(+), 93 deletions(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index f9ad9fb3..79babc60 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -1,9 +1,9 @@ ## read camera trap data package from v1.0-rc1 path_to_json_v1 <- "https://raw.githubusercontent.com/tdwg/camtrap-dp/1.0/example/datapackage.json" -dp_v1_rc1_with_media <- suppressMessages( +dp_v1_with_media <- suppressMessages( read_camtrap_dp(path_to_json_v1) ) -dp_v1_rc1_without_media <- suppressMessages( +dp_v1_without_media <- suppressMessages( read_camtrap_dp(path_to_json_v1, media = FALSE) ) @@ -119,10 +119,10 @@ test_that("output is a list", { expect_true(is.list(dp_without_media)) expect_type(dp_without_media, "list") - expect_true(is.list(dp_v1_rc1_with_media)) - expect_type(dp_v1_rc1_with_media, "list") - expect_true(is.list(dp_v1_rc1_without_media)) - expect_type(dp_v1_rc1_without_media, "list") + expect_true(is.list(dp_v1_with_media)) + expect_type(dp_v1_with_media, "list") + expect_true(is.list(dp_v1_without_media)) + expect_type(dp_v1_without_media, "list") }) test_that("output data slot is a list of length 3", { @@ -136,10 +136,10 @@ test_that("output data slot is a list of length 3", { expect_true("data" %in% names(dp_without_media)) expect_length(dp_without_media$data, 3) - expect_true("data" %in% names(dp_v1_rc1_with_media)) - expect_length(dp_v1_rc1_with_media$data, 3) - expect_true("data" %in% names(dp_v1_rc1_without_media)) - expect_length(dp_v1_rc1_without_media$data, 3) + expect_true("data" %in% names(dp_v1_with_media)) + expect_length(dp_v1_with_media$data, 3) + expect_true("data" %in% names(dp_v1_without_media)) + expect_length(dp_v1_without_media$data, 3) }) test_that("media arg influences only slot media", { @@ -157,17 +157,17 @@ test_that("media arg influences only slot media", { # media is NULL only for data packages imported using `media` = `FALSE` expect_null(dp_without_media$data$media) expect_false(is.null(dp_with_media$data$media)) - expect_null(dp_v1_rc1_without_media$data$media) - expect_false(is.null(dp_v1_rc1_with_media$data$media)) + expect_null(dp_v1_without_media$data$media) + expect_false(is.null(dp_v1_with_media$data$media)) # metadata are the same metadata_with_media <- dp_with_media metadata_with_media$data <- NULL metadata_without_media <- dp_without_media metadata_without_media$data <- NULL expect_identical(metadata_with_media, metadata_without_media) - metadata_with_media_dp_v1_rc1 <- dp_v1_rc1_with_media + metadata_with_media_dp_v1_rc1 <- dp_v1_with_media metadata_with_media_dp_v1_rc1$data <- NULL - metadata_without_media_dp_v1_rc1 <- dp_v1_rc1_without_media + metadata_without_media_dp_v1_rc1 <- dp_v1_without_media metadata_without_media_dp_v1_rc1$data <- NULL expect_identical(metadata_with_media_dp_v1_rc1, metadata_without_media_dp_v1_rc1) @@ -177,8 +177,8 @@ test_that("media arg influences only slot media", { dp_without_media$data$observations ) expect_identical( - dp_v1_rc1_with_media$data$observations, - dp_v1_rc1_without_media$data$observations + dp_v1_with_media$data$observations, + dp_v1_without_media$data$observations ) # deployments are the same expect_identical( @@ -186,8 +186,8 @@ test_that("media arg influences only slot media", { dp_without_media$data$deployments ) expect_identical( - dp_v1_rc1_with_media$data$deployments, - dp_v1_rc1_without_media$data$deployments + dp_v1_with_media$data$deployments, + dp_v1_without_media$data$deployments ) }) @@ -203,10 +203,10 @@ test_that("datapackage data elements are named as in resource names", { resource_names <- frictionless::resources(dp_without_media) expect_true(all(names(dp_without_media$data) %in% resource_names)) # check for v1.0-rc1 - resource_names <- frictionless::resources(dp_v1_rc1_with_media) - expect_true(all(names(dp_v1_rc1_with_media$data) %in% resource_names)) - resource_names <- frictionless::resources(dp_v1_rc1_without_media) - expect_true(all(names(dp_v1_rc1_without_media$data %in% resource_names))) + resource_names <- frictionless::resources(dp_v1_with_media) + expect_true(all(names(dp_v1_with_media$data) %in% resource_names)) + resource_names <- frictionless::resources(dp_v1_without_media) + expect_true(all(names(dp_v1_without_media$data %in% resource_names))) }) test_that("datapackage resources are tibble dataframes", { @@ -224,11 +224,11 @@ test_that("datapackage resources are tibble dataframes", { class(dp_without_media$data$observations))) # check for v1.0-rc1 (only one of the two: chosen for the one with media) expect_true(all(c("tbl_df", "tbl", "data.frame") %in% - class(dp_v1_rc1_with_media$data$deployments))) + class(dp_v1_with_media$data$deployments))) expect_true(all(c("tbl_df", "tbl", "data.frame") %in% - class(dp_v1_rc1_with_media$data$observations))) + class(dp_v1_with_media$data$observations))) expect_true(all(c("tbl_df", "tbl", "data.frame") %in% - class(dp_v1_rc1_with_media$data$media))) + class(dp_v1_with_media$data$media))) }) test_that( @@ -269,34 +269,34 @@ test_that( }) test_that( - "v1.0-rc.1: sc. names and vernacular names in obs match info in metadata", { + "v1.0: sc. names and vernacular names in obs match info in metadata", { taxon_infos <- purrr::map_dfr( - dp_v1_rc1_with_media$taxonomic, + dp_v1_with_media$taxonomic, function(x) x %>% as.data.frame() ) %>% dplyr::tibble() expect_true( - all(names(taxon_infos) %in% names(dp_v1_rc1_with_media$data$observations)) + all(names(taxon_infos) %in% names(dp_v1_with_media$data$observations)) ) # get scientific names from observations and check that they match with # taxonomic info - sc_names <- dp_v1_rc1_with_media$data$observations$scientificName[!is.na( - dp_v1_rc1_with_media$data$observations$scientificName + sc_names <- dp_v1_with_media$data$observations$scientificName[!is.na( + dp_v1_with_media$data$observations$scientificName )] expect_true(all(sc_names %in% taxon_infos$scientificName)) # get vernacular names in English from observations and check that they match # with taxonomic info - en_names <- dp_v1_rc1_with_media$data$observations$vernacularNames.eng[ - !is.na(dp_v1_rc1_with_media$data$observations$vernacularNames.eng) + en_names <- dp_v1_with_media$data$observations$vernacularNames.eng[ + !is.na(dp_v1_with_media$data$observations$vernacularNames.eng) ] expect_true(all(en_names %in% taxon_infos$vernacularNames.eng)) # get vernacular names in Dutch from observations and check that they match # with taxonomic info - nl_names <- dp_v1_rc1_with_media$data$observations$vernacularNames.nld[ + nl_names <- dp_v1_with_media$data$observations$vernacularNames.nld[ !is.na( - dp_v1_rc1_with_media$data$observations$vernacularNames.nld + dp_v1_with_media$data$observations$vernacularNames.nld ) ] expect_true(all(nl_names %in% taxon_infos$vernacularNames.nld)) @@ -322,73 +322,73 @@ test_that("path is deprecated", { test_that( "read deployments v1.0-rc1: latitude follows longitude and both present", { - expect_true("latitude" %in% names(dp_v1_rc1_with_media$data$deployments)) - expect_true("longitude" %in% names(dp_v1_rc1_with_media$data$deployments)) - which(names(dp_v1_rc1_with_media$data$deployments) == "latitude") == - which(names(dp_v1_rc1_with_media$data$deployments) == "longitude") + 1 + expect_true("latitude" %in% names(dp_v1_with_media$data$deployments)) + expect_true("longitude" %in% names(dp_v1_with_media$data$deployments)) + which(names(dp_v1_with_media$data$deployments) == "latitude") == + which(names(dp_v1_with_media$data$deployments) == "longitude") + 1 }) test_that("read deployments v1.0-rc1: eventStart is renamed as start", { - expect_false("eventStart" %in% names(dp_v1_rc1_with_media$data$deployments)) - expect_true("start" %in% names(dp_v1_rc1_with_media$data$deployments)) + expect_false("eventStart" %in% names(dp_v1_with_media$data$deployments)) + expect_true("start" %in% names(dp_v1_with_media$data$deployments)) }) test_that("read deployments v1.0-rc1: eventEnd is renamed as end", { - expect_false("eventEnd" %in% names(dp_v1_rc1_with_media$data$deployments)) - expect_true("end" %in% names(dp_v1_rc1_with_media$data$deployments)) + expect_false("eventEnd" %in% names(dp_v1_with_media$data$deployments)) + expect_true("end" %in% names(dp_v1_with_media$data$deployments)) }) test_that( "read deployments v1.0-rc1: cameraDelay is renamed as cameraInterval", { - expect_false("cameraDelay" %in% names(dp_v1_rc1_with_media$data$deployments)) - expect_true("cameraInterval" %in% names(dp_v1_rc1_with_media$data$deployments)) + expect_false("cameraDelay" %in% names(dp_v1_with_media$data$deployments)) + expect_true("cameraInterval" %in% names(dp_v1_with_media$data$deployments)) }) test_that( "read deployments v1.0-rc1: detectionDistance is a new term and is ignored", { expect_false( - "detectionDistance" %in% names(dp_v1_rc1_with_media$data$deployments) + "detectionDistance" %in% names(dp_v1_with_media$data$deployments) ) }) test_that( "read deployments v1.0-rc1: baitUse is a factor, not a boolean", { - expect_s3_class(dp_v1_rc1_with_media$data$deployments$baitUse, "factor") + expect_s3_class(dp_v1_with_media$data$deployments$baitUse, "factor") baitUse_levels <- c("none", "scent", "food", "visual", "acoustic", "other") expect_identical( - levels(dp_v1_rc1_with_media$data$deployments$baitUse), baitUse_levels + levels(dp_v1_with_media$data$deployments$baitUse), baitUse_levels ) # boolean NA becomes a factor NA - expect_true(all(is.na(dp_v1_rc1_with_media$data$deployments$baitUse))) + expect_true(all(is.na(dp_v1_with_media$data$deployments$baitUse))) } ) test_that("read deployments v1.0-rc1: session is left empty", { - expect_true(all(is.na(dp_v1_rc1_with_media$data$deployments$session))) + expect_true(all(is.na(dp_v1_with_media$data$deployments$session))) }) test_that("read deployments v1.0-rc1: array is left empty", { - expect_true(all(is.na(dp_v1_rc1_with_media$data$deployments$array))) + expect_true(all(is.na(dp_v1_with_media$data$deployments$array))) }) test_that("read deployments v1.0-rc1: deploymentTags is renamed as tags", { expect_false( - "deploymentTags" %in% names(dp_v1_rc1_with_media$data$deployments) + "deploymentTags" %in% names(dp_v1_with_media$data$deployments) ) - expect_true("tags" %in% names(dp_v1_rc1_with_media$data$deployments)) + expect_true("tags" %in% names(dp_v1_with_media$data$deployments)) }) test_that( "read deployments v1.0-rc1: deploymentComments is renamed as comments", { expect_false( - "deploymentComments" %in% names(dp_v1_rc1_with_media$data$deployments) + "deploymentComments" %in% names(dp_v1_with_media$data$deployments) ) - expect_true("comments" %in% names(dp_v1_rc1_with_media$data$deployments)) + expect_true("comments" %in% names(dp_v1_with_media$data$deployments)) } ) test_that("read deployments v1.0-rc1: _id is left empty", { - expect_true(all(is.na(dp_v1_rc1_with_media$data$deployments$`_id`))) + expect_true(all(is.na(dp_v1_with_media$data$deployments$`_id`))) }) test_that( @@ -401,7 +401,7 @@ test_that( media = FALSE )) - cols_deployments_dp_v1_rc1 <- dp_v1_rc1_without_media$data$deployments %>% + cols_deployments_dp_v1 <- dp_v1_without_media$data$deployments %>% names() cols_deployments_dp_v0_1_6 <- dp_without_media$data$deployments %>% names() @@ -410,55 +410,55 @@ test_that( ) test_that("read observations v1.0-rc1: media-based observations are removed", { - expect_true(all(is.na(dp_v1_rc1_with_media$data$observations$mediaID))) + expect_true(all(is.na(dp_v1_with_media$data$observations$mediaID))) }) test_that("read observations v1.0-rc1: eventID is renamed as sequenceID", { - expect_false("eventID" %in% names(dp_v1_rc1_with_media$data$observations)) - expect_true("sequenceID" %in% names(dp_v1_rc1_with_media$data$observations)) + expect_false("eventID" %in% names(dp_v1_with_media$data$observations)) + expect_true("sequenceID" %in% names(dp_v1_with_media$data$observations)) }) test_that("read observations v1.0-rc1: eventStart is renamed as timestamp", { - expect_false("eventStart" %in% names(dp_v1_rc1_with_media$data$observations)) - expect_true("timestamp" %in% names(dp_v1_rc1_with_media$data$observations)) + expect_false("eventStart" %in% names(dp_v1_with_media$data$observations)) + expect_true("timestamp" %in% names(dp_v1_with_media$data$observations)) }) test_that( "read observations v1.0-rc1: eventEnd is a new term and is ignored", { - expect_false("eventEnd" %in% names(dp_v1_rc1_with_media$data$observations)) + expect_false("eventEnd" %in% names(dp_v1_with_media$data$observations)) }) test_that( "read observations v1.0-rc1: observationLevel is a new term and is ignored", { expect_false( - "observationLevel" %in% names(dp_v1_rc1_with_media$data$observations) + "observationLevel" %in% names(dp_v1_with_media$data$observations) ) }) test_that( "read observations v1.0-rc1: cameraSetupType is renamed as cameraSetup", { expect_false( - "cameraSetupType" %in% names(dp_v1_rc1_with_media$data$observations) + "cameraSetupType" %in% names(dp_v1_with_media$data$observations) ) - expect_true("cameraSetup" %in% names(dp_v1_rc1_with_media$data$observations)) + expect_true("cameraSetup" %in% names(dp_v1_with_media$data$observations)) }) test_that("read observations v1.0-rc1: countNew is left empty", { - expect_true(all(is.na(dp_v1_rc1_with_media$data$observations$countNew))) + expect_true(all(is.na(dp_v1_with_media$data$observations$countNew))) }) test_that("read observations v1.0-rc1: higher taxonomic ranks ignored", { expect_false( any(c("kingdom", "phylum", "class", "order", "family", "genus") %in% - names(dp_v1_rc1_with_media$data$observations) + names(dp_v1_with_media$data$observations) ) ) }) test_that( "read observations v1.0-rc1: behavior is renamed as behavior", { - expect_false("behavior" %in% names(dp_v1_rc1_with_media$data$observations)) - expect_true("behaviour" %in% names(dp_v1_rc1_with_media$data$observations)) + expect_false("behavior" %in% names(dp_v1_with_media$data$observations)) + expect_true("behaviour" %in% names(dp_v1_with_media$data$observations)) }) test_that( @@ -466,11 +466,11 @@ test_that( { expect_false( "classificationProbability" %in% - names(dp_v1_rc1_with_media$data$observations) + names(dp_v1_with_media$data$observations) ) expect_true( "classificationConfidence" %in% - names(dp_v1_rc1_with_media$data$observations) + names(dp_v1_with_media$data$observations) ) } ) @@ -478,30 +478,30 @@ test_that( test_that( "read observations v1.0-rc1: observationComments is renamed as comments", { expect_false( - "observationComments" %in% names(dp_v1_rc1_with_media$data$observations) + "observationComments" %in% names(dp_v1_with_media$data$observations) ) - expect_true("comments" %in% names(dp_v1_rc1_with_media$data$observations)) + expect_true("comments" %in% names(dp_v1_with_media$data$observations)) }) test_that("read observations v1.0-rc1: _id is left empty", { - expect_true(all(is.na(dp_v1_rc1_with_media$data$observations$`_id`))) + expect_true(all(is.na(dp_v1_with_media$data$observations$`_id`))) }) test_that( "read observations v1.0-rc1: individualSpeed is renamed as speed", { expect_false( - "individualSpeed" %in% names(dp_v1_rc1_with_media$data$observations) + "individualSpeed" %in% names(dp_v1_with_media$data$observations) ) - expect_true("speed" %in% names(dp_v1_rc1_with_media$data$observations)) + expect_true("speed" %in% names(dp_v1_with_media$data$observations)) }) test_that( "read observations v1.0-rc1: individualPositionRadius is renamed as radius", { expect_false( "individualPositionRadius" %in% - names(dp_v1_rc1_with_media$data$observations) + names(dp_v1_with_media$data$observations) ) - expect_true("radius" %in% names(dp_v1_rc1_with_media$data$observations)) + expect_true("radius" %in% names(dp_v1_with_media$data$observations)) } ) @@ -509,9 +509,9 @@ test_that( "read observations v1.0-rc1: individualPositionAngle is renamed as angle", { expect_false( "individualPositionAngle" %in% - names(dp_v1_rc1_with_media$data$observations) + names(dp_v1_with_media$data$observations) ) - expect_true("angle" %in% names(dp_v1_rc1_with_media$data$observations)) + expect_true("angle" %in% names(dp_v1_with_media$data$observations)) } ) @@ -519,19 +519,19 @@ test_that( "read observations v1.0-rc1: bounding box related columns are not present", { expect_false( "bboxX" %in% - names(dp_v1_rc1_with_media$data$observations) + names(dp_v1_with_media$data$observations) ) expect_false( "bboxY" %in% - names(dp_v1_rc1_with_media$data$observations) + names(dp_v1_with_media$data$observations) ) expect_false( "bboxWidth" %in% - names(dp_v1_rc1_with_media$data$observations) + names(dp_v1_with_media$data$observations) ) expect_false( " bboxHeight" %in% - names(dp_v1_rc1_with_media$data$observations) + names(dp_v1_with_media$data$observations) ) } ) @@ -547,7 +547,7 @@ test_that( file = dp_path, media = FALSE )) - cols_obs_dp_v1_rc1 <- dp_v1_rc1_with_media$data$observations %>% + cols_obs_dp_v1_rc1 <- dp_v1_with_media$data$observations %>% dplyr::select(-dplyr::starts_with("vernacularNames")) %>% names() cols_obs_dp_v0_1_6 <- dp_without_media$data$observations %>% @@ -560,26 +560,26 @@ test_that( ) test_that("read media v1.0-rc1: sequenceID is added", { - expect_true("sequenceID" %in% names(dp_v1_rc1_with_media$data$media)) + expect_true("sequenceID" %in% names(dp_v1_with_media$data$media)) }) test_that( "read media v1.0-rc1: filePublic is a new term in v1.0-rc1 and is ignored", { - expect_false("filePublic" %in% names(dp_v1_rc1_with_media$data$media)) + expect_false("filePublic" %in% names(dp_v1_with_media$data$media)) }) test_that("read media v1.0-rc1: favorite is renamed as favourite", { - expect_false("favorite" %in% names(dp_v1_rc1_with_media$data$media)) - expect_true("favourite" %in% names(dp_v1_rc1_with_media$data$media)) + expect_false("favorite" %in% names(dp_v1_with_media$data$media)) + expect_true("favourite" %in% names(dp_v1_with_media$data$media)) }) test_that("read media v1.0-rc1: mediaComments is renamed as comments", { - expect_false("mediaComments" %in% names(dp_v1_rc1_with_media$data$media)) - expect_true("comments" %in% names(dp_v1_rc1_with_media$data$media)) + expect_false("mediaComments" %in% names(dp_v1_with_media$data$media)) + expect_true("comments" %in% names(dp_v1_with_media$data$media)) }) test_that("read media v1.0-rc1: _id is left empty", { - expect_true(all(is.na(dp_v1_rc1_with_media$data$media$`_id`))) + expect_true(all(is.na(dp_v1_with_media$data$media$`_id`))) }) test_that( @@ -591,7 +591,7 @@ test_that( file = dp_path, media = TRUE )) - cols_media_dp_v1_rc1 <- dp_v1_rc1_with_media$data$media %>% + cols_media_dp_v1_rc1 <- dp_v1_with_media$data$media %>% names() cols_media_dp_v0_1_6 <- dp_with_media$data$media %>% names() From 89c02024d2e421ff467a40a7bf22173693531af9 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:49:03 +0100 Subject: [PATCH 11/39] refer to `v1.0` not release candidate --- tests/testthat/test-read_camtrap_dp.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index 79babc60..ecabeddf 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -392,7 +392,7 @@ test_that("read deployments v1.0-rc1: _id is left empty", { }) test_that( - "all cols `v0.1.6:deployments` are present in `v1.0-rc1:deployments`", { + "all cols `v0.1.6:deployments` are present in `v1.0`", { dp_path <- system.file("extdata", "mica", "datapackage.json", package = "camtraptor" ) From 0615366ecd2585a41a6344b78c75960105b20638 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:53:14 +0100 Subject: [PATCH 12/39] downconvert `deployments.cameraDepth` by removing it Co-Authored-By: Peter Desmet --- R/zzz.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/zzz.R b/R/zzz.R index 92e1075b..422dce8a 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -571,6 +571,8 @@ convert_deployments_to_0.1.6 <- function(package, from = "1.0") { } # ignore detectionDistance deployments$detectionDistance <- NULL + # ignore cameraDepth + deployments$cameraDepth <- NULL if ("baitUse" %in% names(deployments)) { # baitUse values in version 0.1.6 bait_uses_old <- c("none", "scent", "food", "visual", "acoustic", "other") From 61fcd0d8b557a6e0fa784bf0f5216d3fab6acac3 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:54:59 +0100 Subject: [PATCH 13/39] remove reference to release candidate --- tests/testthat/test-read_camtrap_dp.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index ecabeddf..787c33ea 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -405,7 +405,7 @@ test_that( names() cols_deployments_dp_v0_1_6 <- dp_without_media$data$deployments %>% names() - expect_identical(cols_deployments_dp_v0_1_6, cols_deployments_dp_v1_rc1) + expect_identical(cols_deployments_dp_v0_1_6, cols_deployments_dp_v1) } ) From 5f210ef741c4dac562946ec5c8c0bbea18809511 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:02:48 +0100 Subject: [PATCH 14/39] remove references to release candidate --- tests/testthat/test-read_camtrap_dp.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index 787c33ea..5843454f 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -537,9 +537,9 @@ test_that( ) test_that( - "all cols `v0.1.6:observations` are present in `v1.0-rc1:observations`", { + "all cols `v0.1.6:observations` are present in `v1.0`", { # notice that cols with vernacular names are different due to use of ISO - # 693-3 in v1.0-rc1 vs ISO 693-2 in v0.1.6. + # 693-3 in v1.0 vs ISO 693-2 in v0.1.6. dp_path <- system.file("extdata", "mica", "datapackage.json", package = "camtraptor" ) @@ -547,14 +547,14 @@ test_that( file = dp_path, media = FALSE )) - cols_obs_dp_v1_rc1 <- dp_v1_with_media$data$observations %>% + cols_obs_dp_v1 <- dp_v1_with_media$data$observations %>% dplyr::select(-dplyr::starts_with("vernacularNames")) %>% names() cols_obs_dp_v0_1_6 <- dp_without_media$data$observations %>% dplyr::select(-dplyr::starts_with("vernacularNames")) %>% names() expect_true( - all(cols_obs_dp_v0_1_6 %in% cols_obs_dp_v1_rc1) + all(cols_obs_dp_v0_1_6 %in% cols_obs_dp_v1) ) } ) From 7761d29fee0e3b60dde99c45eae40ea7b495c417 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:09:06 +0100 Subject: [PATCH 15/39] also add taxonIDReference if missing when downconverting --- R/zzz.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/zzz.R b/R/zzz.R index 422dce8a..5e026c9e 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -827,7 +827,13 @@ convert_observations_to_0.1.6 <- function(package, from = "1.0") { observations <- observations %>% dplyr::select(-dplyr::starts_with("bbox")) # add taxonID if missing if(!"taxonID" %in% colnames(observations)){ - observations <- observations %>% dplyr::mutate(taxonID = NA_integer_) + observations <- observations %>% + dplyr::mutate(taxonID = NA_integer_) + } + # add taxonIDReference if missing + if(!"taxonIDReference" %in% colnames(observations)){ + observations <- observations %>% + dplyr::mutate(taxonIDReference = NA_character_) } package$data$observations <- observations From 391c027af242b4d7a2a42c4e4371fde971bda8c7 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:23:01 +0100 Subject: [PATCH 16/39] remove code from #282 --- tests/testthat/test-read_camtrap_dp.R | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index 5843454f..6c7a7cdf 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -61,11 +61,6 @@ test_that("test warnings while reading files with parsing issues", { "`readr::problems()`." ) ) - problems_deploys <- readr::problems(dp_issues$data$deployments) - expect_identical(nrow(problems_deploys), 2L) - expect_identical(problems_deploys$row, c(1L,2L)) - expect_identical(problems_deploys$col, c(7L,7L)) - expect_identical(problems_deploys$expected, rep("date like %Y-%m-%dT%H:%M:%S%z", 2)) # warning on observations expect_identical( @@ -76,11 +71,6 @@ test_that("test warnings while reading files with parsing issues", { "`readr::problems()`." ) ) - problems_obs <- readr::problems(dp_issues$data$observations) - expect_identical(nrow(problems_obs), 2L) - expect_identical(problems_obs$row, c(1L,2L)) - expect_identical(problems_obs$col, c(5L,5L)) - expect_identical(problems_obs$expected, rep("date like %Y-%m-%dT%H:%M:%S%z", 2)) # warning on media expect_identical( @@ -91,11 +81,6 @@ test_that("test warnings while reading files with parsing issues", { "`readr::problems()`." ) ) - problems_media <- readr::problems(dp_issues$data$media) - expect_identical(nrow(problems_media), 1L) - expect_identical(problems_media$row, 2L) - expect_identical(problems_media$col, 5L) - expect_identical(problems_media$expected, "date like %Y-%m-%dT%H:%M:%S%z") }) test_that("media is checked properly", { @@ -363,7 +348,7 @@ test_that( } ) -test_that("read deployments v1.0-rc1: session is left empty", { +test_that("read deployments v1.0: session is left empty", { expect_true(all(is.na(dp_v1_with_media$data$deployments$session))) }) From 8a31e593b0b327e8d29f474ea9401dfb91fcfcc3 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:35:28 +0100 Subject: [PATCH 17/39] remove references to release candidate --- R/zzz.R | 2 +- tests/testthat/test-read_camtrap_dp.R | 70 +++++++++++++-------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 5e026c9e..04e7f586 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -690,7 +690,7 @@ convert_media_to_0.1.6 <- function(package, from = "1.0") { event_obs <- observations %>% dplyr::filter(is.na(.data$mediaID)) %>% dplyr::select("eventID", "deploymentID", "eventStart", "eventEnd") %>% - # eventID is not anymore required in v1.0-rc1, remove where not present + # eventID is not anymore required in v1.0, remove where not present dplyr::filter(!is.na(.data$eventID)) # Join on deploymentID and timestamp between eventStart and eventEnd diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index 6c7a7cdf..04832286 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -1,4 +1,4 @@ -## read camera trap data package from v1.0-rc1 +## read camera trap data package from v1.0 path_to_json_v1 <- "https://raw.githubusercontent.com/tdwg/camtrap-dp/1.0/example/datapackage.json" dp_v1_with_media <- suppressMessages( read_camtrap_dp(path_to_json_v1) @@ -187,7 +187,7 @@ test_that("datapackage data elements are named as in resource names", { )) resource_names <- frictionless::resources(dp_without_media) expect_true(all(names(dp_without_media$data) %in% resource_names)) - # check for v1.0-rc1 + # check for v1.0 resource_names <- frictionless::resources(dp_v1_with_media) expect_true(all(names(dp_v1_with_media$data) %in% resource_names)) resource_names <- frictionless::resources(dp_v1_without_media) @@ -207,7 +207,7 @@ test_that("datapackage resources are tibble dataframes", { class(dp_without_media$data$deployments))) expect_true(all(c("tbl_df", "tbl", "data.frame") %in% class(dp_without_media$data$observations))) - # check for v1.0-rc1 (only one of the two: chosen for the one with media) + # check for v1.0 (only one of the two: chosen for the one with media) expect_true(all(c("tbl_df", "tbl", "data.frame") %in% class(dp_v1_with_media$data$deployments))) expect_true(all(c("tbl_df", "tbl", "data.frame") %in% @@ -306,38 +306,38 @@ test_that("path is deprecated", { }) test_that( - "read deployments v1.0-rc1: latitude follows longitude and both present", { + "read deployments v1.0: latitude follows longitude and both present", { expect_true("latitude" %in% names(dp_v1_with_media$data$deployments)) expect_true("longitude" %in% names(dp_v1_with_media$data$deployments)) which(names(dp_v1_with_media$data$deployments) == "latitude") == which(names(dp_v1_with_media$data$deployments) == "longitude") + 1 }) -test_that("read deployments v1.0-rc1: eventStart is renamed as start", { +test_that("read deployments v1.0: eventStart is renamed as start", { expect_false("eventStart" %in% names(dp_v1_with_media$data$deployments)) expect_true("start" %in% names(dp_v1_with_media$data$deployments)) }) -test_that("read deployments v1.0-rc1: eventEnd is renamed as end", { +test_that("read deployments v1.0: eventEnd is renamed as end", { expect_false("eventEnd" %in% names(dp_v1_with_media$data$deployments)) expect_true("end" %in% names(dp_v1_with_media$data$deployments)) }) test_that( - "read deployments v1.0-rc1: cameraDelay is renamed as cameraInterval", { + "read deployments v1.0: cameraDelay is renamed as cameraInterval", { expect_false("cameraDelay" %in% names(dp_v1_with_media$data$deployments)) expect_true("cameraInterval" %in% names(dp_v1_with_media$data$deployments)) }) test_that( - "read deployments v1.0-rc1: detectionDistance is a new term and is ignored", { + "read deployments v1.0: detectionDistance is a new term and is ignored", { expect_false( "detectionDistance" %in% names(dp_v1_with_media$data$deployments) ) }) test_that( - "read deployments v1.0-rc1: baitUse is a factor, not a boolean", { + "read deployments v1.0: baitUse is a factor, not a boolean", { expect_s3_class(dp_v1_with_media$data$deployments$baitUse, "factor") baitUse_levels <- c("none", "scent", "food", "visual", "acoustic", "other") expect_identical( @@ -352,11 +352,11 @@ test_that("read deployments v1.0: session is left empty", { expect_true(all(is.na(dp_v1_with_media$data$deployments$session))) }) -test_that("read deployments v1.0-rc1: array is left empty", { +test_that("read deployments v1.0: array is left empty", { expect_true(all(is.na(dp_v1_with_media$data$deployments$array))) }) -test_that("read deployments v1.0-rc1: deploymentTags is renamed as tags", { +test_that("read deployments v1.0: deploymentTags is renamed as tags", { expect_false( "deploymentTags" %in% names(dp_v1_with_media$data$deployments) ) @@ -364,7 +364,7 @@ test_that("read deployments v1.0-rc1: deploymentTags is renamed as tags", { }) test_that( - "read deployments v1.0-rc1: deploymentComments is renamed as comments", { + "read deployments v1.0: deploymentComments is renamed as comments", { expect_false( "deploymentComments" %in% names(dp_v1_with_media$data$deployments) ) @@ -372,7 +372,7 @@ test_that( } ) -test_that("read deployments v1.0-rc1: _id is left empty", { +test_that("read deployments v1.0: _id is left empty", { expect_true(all(is.na(dp_v1_with_media$data$deployments$`_id`))) }) @@ -394,45 +394,45 @@ test_that( } ) -test_that("read observations v1.0-rc1: media-based observations are removed", { +test_that("read observations v1.0: media-based observations are removed", { expect_true(all(is.na(dp_v1_with_media$data$observations$mediaID))) }) -test_that("read observations v1.0-rc1: eventID is renamed as sequenceID", { +test_that("read observations v1.0: eventID is renamed as sequenceID", { expect_false("eventID" %in% names(dp_v1_with_media$data$observations)) expect_true("sequenceID" %in% names(dp_v1_with_media$data$observations)) }) -test_that("read observations v1.0-rc1: eventStart is renamed as timestamp", { +test_that("read observations v1.0: eventStart is renamed as timestamp", { expect_false("eventStart" %in% names(dp_v1_with_media$data$observations)) expect_true("timestamp" %in% names(dp_v1_with_media$data$observations)) }) test_that( - "read observations v1.0-rc1: eventEnd is a new term and is ignored", { + "read observations v1.0: eventEnd is a new term and is ignored", { expect_false("eventEnd" %in% names(dp_v1_with_media$data$observations)) }) test_that( - "read observations v1.0-rc1: observationLevel is a new term and is ignored", { + "read observations v1.0: observationLevel is a new term and is ignored", { expect_false( "observationLevel" %in% names(dp_v1_with_media$data$observations) ) }) test_that( - "read observations v1.0-rc1: cameraSetupType is renamed as cameraSetup", { + "read observations v1.0: cameraSetupType is renamed as cameraSetup", { expect_false( "cameraSetupType" %in% names(dp_v1_with_media$data$observations) ) expect_true("cameraSetup" %in% names(dp_v1_with_media$data$observations)) }) -test_that("read observations v1.0-rc1: countNew is left empty", { +test_that("read observations v1.0: countNew is left empty", { expect_true(all(is.na(dp_v1_with_media$data$observations$countNew))) }) -test_that("read observations v1.0-rc1: higher taxonomic ranks ignored", { +test_that("read observations v1.0: higher taxonomic ranks ignored", { expect_false( any(c("kingdom", "phylum", "class", "order", "family", "genus") %in% names(dp_v1_with_media$data$observations) @@ -441,13 +441,13 @@ test_that("read observations v1.0-rc1: higher taxonomic ranks ignored", { }) test_that( - "read observations v1.0-rc1: behavior is renamed as behavior", { + "read observations v1.0: behavior is renamed as behavior", { expect_false("behavior" %in% names(dp_v1_with_media$data$observations)) expect_true("behaviour" %in% names(dp_v1_with_media$data$observations)) }) test_that( - "read observations v1.0-rc1: classificationProbability renamed as classificationConfidence", + "read observations v1.0: classificationProbability renamed as classificationConfidence", { expect_false( "classificationProbability" %in% @@ -461,19 +461,19 @@ test_that( ) test_that( - "read observations v1.0-rc1: observationComments is renamed as comments", { + "read observations v1.0: observationComments is renamed as comments", { expect_false( "observationComments" %in% names(dp_v1_with_media$data$observations) ) expect_true("comments" %in% names(dp_v1_with_media$data$observations)) }) -test_that("read observations v1.0-rc1: _id is left empty", { +test_that("read observations v1.0: _id is left empty", { expect_true(all(is.na(dp_v1_with_media$data$observations$`_id`))) }) test_that( - "read observations v1.0-rc1: individualSpeed is renamed as speed", { + "read observations v1.0: individualSpeed is renamed as speed", { expect_false( "individualSpeed" %in% names(dp_v1_with_media$data$observations) ) @@ -481,7 +481,7 @@ test_that( }) test_that( - "read observations v1.0-rc1: individualPositionRadius is renamed as radius", { + "read observations v1.0: individualPositionRadius is renamed as radius", { expect_false( "individualPositionRadius" %in% names(dp_v1_with_media$data$observations) @@ -491,7 +491,7 @@ test_that( ) test_that( - "read observations v1.0-rc1: individualPositionAngle is renamed as angle", { + "read observations v1.0: individualPositionAngle is renamed as angle", { expect_false( "individualPositionAngle" %in% names(dp_v1_with_media$data$observations) @@ -501,7 +501,7 @@ test_that( ) test_that( - "read observations v1.0-rc1: bounding box related columns are not present", { + "read observations v1.0: bounding box related columns are not present", { expect_false( "bboxX" %in% names(dp_v1_with_media$data$observations) @@ -544,31 +544,31 @@ test_that( } ) -test_that("read media v1.0-rc1: sequenceID is added", { +test_that("read media v1.0: sequenceID is added", { expect_true("sequenceID" %in% names(dp_v1_with_media$data$media)) }) test_that( - "read media v1.0-rc1: filePublic is a new term in v1.0-rc1 and is ignored", { + "read media v1.0: filePublic is a new term in v1.0 and is ignored", { expect_false("filePublic" %in% names(dp_v1_with_media$data$media)) }) -test_that("read media v1.0-rc1: favorite is renamed as favourite", { +test_that("read media v1.0: favorite is renamed as favourite", { expect_false("favorite" %in% names(dp_v1_with_media$data$media)) expect_true("favourite" %in% names(dp_v1_with_media$data$media)) }) -test_that("read media v1.0-rc1: mediaComments is renamed as comments", { +test_that("read media v1.0: mediaComments is renamed as comments", { expect_false("mediaComments" %in% names(dp_v1_with_media$data$media)) expect_true("comments" %in% names(dp_v1_with_media$data$media)) }) -test_that("read media v1.0-rc1: _id is left empty", { +test_that("read media v1.0: _id is left empty", { expect_true(all(is.na(dp_v1_with_media$data$media$`_id`))) }) test_that( - "all cols `v0.1.6:media` are present in `v1.0-rc1:media`", { + "all cols `v0.1.6:media` are present in `v1.0:media`", { dp_path <- system.file("extdata", "mica", "datapackage.json", package = "camtraptor" ) From 62c980d8c6236d01327c361419eaf39be8e1f0a4 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:39:16 +0100 Subject: [PATCH 18/39] recode captureMethod factor in downconversion --- DESCRIPTION | 1 + R/zzz.R | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index 41bdb40b..8545c607 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,6 +34,7 @@ Imports: assertthat, dplyr (>= 1.1.0), EML, + forcats, frictionless, glue, htmltools, diff --git a/R/zzz.R b/R/zzz.R index 04e7f586..b1857041 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -723,6 +723,14 @@ convert_media_to_0.1.6 <- function(package, from = "1.0") { dplyr::mutate("_id" = NA) } + # convert captureMethod value to v1.6.0 terms + media <- media %>% + dplyr::mutate( + captureMethod = + forcats::fct_recode(captureMethod, + motionDetection = "activityDetection") + ) + package$data$media <- media return(package) } From 08991461177b4057bfacfafdec39b5e67b82d24a Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:43:25 +0100 Subject: [PATCH 19/39] don't depend on forcats --- DESCRIPTION | 1 - R/zzz.R | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8545c607..41bdb40b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,7 +34,6 @@ Imports: assertthat, dplyr (>= 1.1.0), EML, - forcats, frictionless, glue, htmltools, diff --git a/R/zzz.R b/R/zzz.R index b1857041..ae907603 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -724,12 +724,14 @@ convert_media_to_0.1.6 <- function(package, from = "1.0") { } # convert captureMethod value to v1.6.0 terms - media <- media %>% + media <- media %>% dplyr::mutate( - captureMethod = - forcats::fct_recode(captureMethod, - motionDetection = "activityDetection") + captureMethod = factor( + ifelse(captureMethod == "activityDetection", + "motionDetection", + as.character(captureMethod)) ) + ) package$data$media <- media return(package) From d8e89c56ab606854cc49c988903f34082689c45f Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:47:46 +0100 Subject: [PATCH 20/39] add test for replacing values in media.captureMethod --- tests/testthat/test-read_camtrap_dp.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index 04832286..e0a37335 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -583,3 +583,13 @@ test_that( expect_identical(cols_media_dp_v1_rc1, cols_media_dp_v0_1_6) } ) + +test_that("v1.0:media$captureMethod values are replaced with v0.1.6 values",{ + expect_false( + "activityDetection" %in% dp_v1_with_media$data$media$captureMethod + ) + expect_identical( + levels(dp_v1_with_media$data$media$captureMethod), + c("motionDetection", "timeLapse") + ) +}) \ No newline at end of file From 2ea4878b7c12930f9dee39f2303987a0444951ab Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:56:26 +0100 Subject: [PATCH 21/39] add test for downconverting captureMethod values in package$project --- tests/testthat/test-read_camtrap_dp.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index e0a37335..40be0573 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -592,4 +592,14 @@ test_that("v1.0:media$captureMethod values are replaced with v0.1.6 values",{ levels(dp_v1_with_media$data$media$captureMethod), c("motionDetection", "timeLapse") ) +}) + +test_that("v1.0:project$captureMethod values are replaced with v0.1.6 values", { + expect_false( + "activityDetection" %in% dp_v1_with_media$project$captureMethod + ) + expect_identical( + dp_v1_with_media$project$captureMethod, + c("motionDetection", "timeLapse") + ) }) \ No newline at end of file From dc42fec831645762a4ca80769c5a02712608bd87 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:56:51 +0100 Subject: [PATCH 22/39] convert captureMethod to v0.1.6 values in `package$project` --- R/zzz.R | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/R/zzz.R b/R/zzz.R index ae907603..94fe70b5 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -536,6 +536,15 @@ convert_metadata_to_0.1.6 <- function(package, from = "1.0"){ dplyr::filter(.data$role == "rightsHolder") %>% dplyr::slice(1) %>% dplyr::pull(.data$title) + + # downconvert `captureMethod` to values from Camtrap DP version v0.1.6 + package$project$captureMethod <- + dplyr::case_match( + .default = package$project$captureMethod, + package$project$captureMethod, + "activityDetection" ~ "motionDetection" + ) + return(package) } From 395506de2a2e937d070473a82d7b0f828efecce9 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:59:32 +0100 Subject: [PATCH 23/39] remove references to release candidate --- tests/testthat/test-read_camtrap_dp.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index 40be0573..85b836ac 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -150,12 +150,12 @@ test_that("media arg influences only slot media", { metadata_without_media <- dp_without_media metadata_without_media$data <- NULL expect_identical(metadata_with_media, metadata_without_media) - metadata_with_media_dp_v1_rc1 <- dp_v1_with_media - metadata_with_media_dp_v1_rc1$data <- NULL - metadata_without_media_dp_v1_rc1 <- dp_v1_without_media - metadata_without_media_dp_v1_rc1$data <- NULL - expect_identical(metadata_with_media_dp_v1_rc1, - metadata_without_media_dp_v1_rc1) + metadata_with_media_dp_v1 <- dp_v1_with_media + metadata_with_media_dp_v1$data <- NULL + metadata_without_media_dp_v1 <- dp_v1_without_media + metadata_without_media_dp_v1$data <- NULL + expect_identical(metadata_with_media_dp_v1, + metadata_without_media_dp_v1) # observations are the same expect_identical( dp_with_media$data$observations, @@ -576,11 +576,11 @@ test_that( file = dp_path, media = TRUE )) - cols_media_dp_v1_rc1 <- dp_v1_with_media$data$media %>% + cols_media_dp_v1 <- dp_v1_with_media$data$media %>% names() cols_media_dp_v0_1_6 <- dp_with_media$data$media %>% names() - expect_identical(cols_media_dp_v1_rc1, cols_media_dp_v0_1_6) + expect_identical(cols_media_dp_v1, cols_media_dp_v0_1_6) } ) From 0813325490b2cdac5d34d534814b75f3421fda03 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:05:49 +0100 Subject: [PATCH 24/39] end file on linebreak --- tests/testthat/test-read_camtrap_dp.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index 85b836ac..4a23de73 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -602,4 +602,4 @@ test_that("v1.0:project$captureMethod values are replaced with v0.1.6 values", { dp_v1_with_media$project$captureMethod, c("motionDetection", "timeLapse") ) -}) \ No newline at end of file +}) From fb477ef7b5a57cba326da1f331edcebb44e164b5 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Mon, 6 Nov 2023 11:37:54 +0100 Subject: [PATCH 25/39] split off test, skip if no NA in deployments.csv --- tests/testthat/test-read_camtrap_dp.R | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index 4a23de73..a61eccd6 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -343,11 +343,23 @@ test_that( expect_identical( levels(dp_v1_with_media$data$deployments$baitUse), baitUse_levels ) - # boolean NA becomes a factor NA - expect_true(all(is.na(dp_v1_with_media$data$deployments$baitUse))) } ) +test_that("read deployments v1.0: boolean NA becomes a factor NA", { + ## no longer present in the example package! + skip_if_not(any(is.na( + readr::read_csv( + file.path(dirname(path_to_json_v1), "deployments.csv"), + show_col_types = FALSE, + col_select = "baitUse" + ) + )), + message = "There are no NA values present in deployments.baitUse") + + expect_true(all(is.na(dp_v1_with_media$data$deployments$baitUse))) +}) + test_that("read deployments v1.0: session is left empty", { expect_true(all(is.na(dp_v1_with_media$data$deployments$session))) }) From d703dfb2c5b7c602b5e09ba8c31c6aae79125a63 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:12:39 +0100 Subject: [PATCH 26/39] always keep deploymentGroup info, see comment in #286 https: //github.com/inbo/camtraptor/pull/286#issuecomment-1794656381 Co-Authored-By: Peter Desmet --- R/zzz.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 94fe70b5..a0ac1300 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -625,12 +625,16 @@ convert_deployments_to_0.1.6 <- function(package, from = "1.0") { # map to session and then remove deployments <- deployments %>% dplyr::mutate(session = dplyr::case_when( - is.na(.data$session) ~.data$deploymentGroups, - is.na(.data$deploymentGroups) ~ .data$session, !is.na(.data$deploymentGroups) & !is.na(.data$session) ~ stringr::str_c(.data$session, .data$deploymentGroups, - sep = " | "))) %>% + sep = " | "), + !is.na(.data$deploymentGroups) & is.na(.data$session) ~ + .data$deploymentGroups, + is.na(.data$deploymentGroups) & !is.na(.data$session) ~ + .data$session, + # if there is no value for neither deploymentGroups or session: + .default = NA)) %>% dplyr::select(-"deploymentGroups") } if ("array" %in% names(deployments)) { From 9d8361a05313d94f575b3201f8ffa8ee06658710 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:18:13 +0100 Subject: [PATCH 27/39] avoid writeLines so message can be silenced --- R/zzz.R | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index a0ac1300..d8e694dd 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -460,14 +460,13 @@ convert_to_0.1.6 <- function(package, from = "1.0", media = TRUE){ ) # notify about conversion - message( - writeLines( - c( - "The dataset uses Camtrap DP version 1.0, it has been converted to 0.1.6.", - "See https://inbo.github.io/camtraptor/#camtrap-dp for details." - ) + message(paste0( + collapse = "\n", + c( + "The dataset uses Camtrap DP version 1.0, it has been converted to 0.1.6.", + "See https://inbo.github.io/camtraptor/#camtrap-dp for details." ) - ) + )) # convert metadata package <- convert_metadata_to_0.1.6(package, from) # convert deployments From 706592e3e4b9f7626c6704a41d5d823524bd18a8 Mon Sep 17 00:00:00 2001 From: Pieter Huybrechts <48065851+PietrH@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:19:13 +0100 Subject: [PATCH 28/39] skip test if there are no NA in deploymentGroups, pass if one row is processed correctly --- tests/testthat/test-read_camtrap_dp.R | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index a61eccd6..05c38ea9 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -360,9 +360,19 @@ test_that("read deployments v1.0: boolean NA becomes a factor NA", { expect_true(all(is.na(dp_v1_with_media$data$deployments$baitUse))) }) -test_that("read deployments v1.0: session is left empty", { - expect_true(all(is.na(dp_v1_with_media$data$deployments$session))) -}) +test_that( + "read deployments v1.0: session is left empty when deploymentGroups is NA",{ + skip_if(all(!is.na( + readr::read_csv( + file.path(dirname(path_to_json_v1), "deployments.csv"), + show_col_types = FALSE, + col_select = "deploymentGroups" + ) + )), message = "All rows have value for deploymentGroups in deployments.csv") + expect_true(any(is.na( + dp_v1_with_media$data$deployments$session + ))) + }) test_that("read deployments v1.0: array is left empty", { expect_true(all(is.na(dp_v1_with_media$data$deployments$array))) From 6878f410c4fd7a4edc2d67fb480e3a73ad16ac79 Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Wed, 8 Nov 2023 09:56:13 +0100 Subject: [PATCH 29/39] Update Camtrap DP section in README --- README.Rmd | 2 +- README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.Rmd b/README.Rmd index aa08e1b2..9ed4514e 100644 --- a/README.Rmd +++ b/README.Rmd @@ -27,7 +27,7 @@ Camtraptor is an R package to read, explore and visualize Camera Trap Data Packa ## Camtrap DP -Camtraptor currently uses the legacy Camtrap DP 0.1.6 for its internal data model. `read_camtrap_dp()` will automatically down-convert Camtrap DP 1.0-rc.1 datasets to that legacy model to avoid introducing breaking changes. The downside is that some newer properties like `media.filePublic` and `observations.eventEnd` are ignored when reading data. +Camtraptor currently uses the legacy Camtrap DP 0.1.6 for its internal data model. `read_camtrap_dp()` will automatically down-convert Camtrap DP 1.0 datasets to that legacy model to avoid introducing breaking changes. The downside is that some newer properties like `deployments.cameraDepth`, `media.filePublic` and `observations.eventEnd` are removed when reading data. The upcoming [camtraptor v1.0](https://github.com/inbo/camtraptor/milestone/3) will update the internal data model to Camtrap DP 1.0 and drop support for Camtrap DP 0.1.6. This is a breaking change that will be accompanied by a number of other major changes. Future versions of camtraptor will always use the latest version of Camtrap DP and up-convert legacy datasets to that model. diff --git a/README.md b/README.md index 1d346c16..7ed8f3b8 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,10 @@ effort, and plot these data on a map. Camtraptor currently uses the legacy Camtrap DP 0.1.6 for its internal data model. `read_camtrap_dp()` will automatically down-convert Camtrap -DP 1.0-rc.1 datasets to that legacy model to avoid introducing breaking +DP 1.0 datasets to that legacy model to avoid introducing breaking changes. The downside is that some newer properties like -`media.filePublic` and `observations.eventEnd` are ignored when reading -data. +`deployments.cameraDepth`, `media.filePublic` and +`observations.eventEnd` are removed when reading data. The upcoming [camtraptor v1.0](https://github.com/inbo/camtraptor/milestone/3) will update the From 3f2b840826c01610bac4e664e87ceb056a833085 Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Wed, 8 Nov 2023 10:05:40 +0100 Subject: [PATCH 30/39] Update URL of Camtrap DP --- DESCRIPTION | 2 +- R/data.R | 2 +- R/get_prefixes.R | 2 +- R/map_dep.R | 2 +- R/read_camtrap_dp.R | 2 +- R/read_wi.R | 10 +++++----- R/write_dwc.R | 2 +- R/write_eml.R | 6 +++--- README.Rmd | 2 +- README.md | 9 ++++----- man/map_dep.Rd | 2 +- man/mica.Rd | 2 +- man/read_camtrap_dp.Rd | 2 +- man/read_wi.Rd | 2 +- man/write_dwc.Rd | 2 +- man/write_eml.Rd | 4 +++- 16 files changed, 27 insertions(+), 26 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 41bdb40b..bae56668 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,7 +22,7 @@ Authors@R: c( role = "fnd", comment = "https://lifewatch.be") ) Description: Read, explore and visualize Camera Trap Data Packages (Camtrap DP). - 'Camtrap DP' () is a community developed + 'Camtrap DP' () is a community developed data exchange format for this type of data. With camtraptor you can read and filter data, create overviews of observed species, relative abundance or effort, and plot these data on a map. diff --git a/R/data.R b/R/data.R index 0c25c0d5..08b0937b 100644 --- a/R/data.R +++ b/R/data.R @@ -1,6 +1,6 @@ #' Sample of Camtrap DP formatted data #' -#' A sample [Camera Trap Data Package](https://tdwg.github.io/camtrap-dp) as +#' A sample [Camera Trap Data Package](https://camtrap-dp.tdwg.org) as #' read by [read_camtrap_dp()]. #' The source data are derived from the [Camtrap DP example dataset]( #' https://github.com/tdwg/camtrap-dp/tree/ad0278ef86ef518dacfb306c598dce97667cfb81/example) diff --git a/R/get_prefixes.R b/R/get_prefixes.R index 099b1ab1..95ce2fef 100644 --- a/R/get_prefixes.R +++ b/R/get_prefixes.R @@ -3,7 +3,7 @@ #' Stores prefixes for info shown while hovering over a deployment with the #' mouse. #' List fields in deployments as in -#' . +#' . #' #' Returns a data.frame of all prefixes with the following columns: #' - `info`: Deployment info. diff --git a/R/map_dep.R b/R/map_dep.R index d82582e2..7efbf19a 100644 --- a/R/map_dep.R +++ b/R/map_dep.R @@ -57,7 +57,7 @@ #' - `latitude` #' - `longitude` #' -#' See the [Deployment](https://tdwg.github.io/camtrap-dp/data/#deployments) +#' See the [Deployment](https://camtrap-dp.tdwg.org/data/#deployments) #' section of Camtrap DP for the full list of columns you can use. #' @param palette The palette name or the colour function that values will be #' mapped to. diff --git a/R/read_camtrap_dp.R b/R/read_camtrap_dp.R index 834c0245..6fcd5ec3 100644 --- a/R/read_camtrap_dp.R +++ b/R/read_camtrap_dp.R @@ -1,7 +1,7 @@ #' Read a Camtrap DP #' #' Reads files from a [Camera Trap Data Package]( -#' https://tdwg.github.io/camtrap-dp) into memory. +#' https://camtrap-dp.tdwg.org) into memory. #' All datetime information is automatically transformed to Coordinated #' Universal Time (UTC). #' Vernacular names found in the metadata (`package$taxonomic`) are added to the diff --git a/R/read_wi.R b/R/read_wi.R index 2dbbe585..7e8f88be 100644 --- a/R/read_wi.R +++ b/R/read_wi.R @@ -7,7 +7,7 @@ #' [private](https://www.wildlifeinsights.org/get-started/download/private) #' download. #' The function transforms data and metadata to a [Camera Trap Data Package]( -#' https://tdwg.github.io/camtrap-dp) which can be written to file with +#' https://camtrap-dp.tdwg.org) which can be written to file with #' [frictionless::write_package()]. #' #' **The function has only been tested on image-based projects.** @@ -61,7 +61,7 @@ read_wi <- function(directory = ".") { # Create package package <- frictionless::create_package() # Also sets profile, resources - # Set metadata properties, see https://tdwg.github.io/camtrap-dp/metadata + # Set metadata properties, see https://camtrap-dp.tdwg.org/metadata package$name <- basename(directory) # Unique name if unchanged from WI export zip package$id <- wi_project$ark_id # (e.g. http://n2t.net/ark:/63614/w12001317) package$created <- lubridate::format_ISO8601(lubridate::now()) @@ -229,7 +229,7 @@ read_wi <- function(directory = ".") { # packageID = "" ) - # Create deployments, see https://tdwg.github.io/camtrap-dp/data/#deployments + # Create deployments, see https://camtrap-dp.tdwg.org/data/#deployments deployments <- wi_deployments %>% dplyr::left_join(wi_cameras, by = c("project_id", "camera_id")) %>% @@ -298,7 +298,7 @@ read_wi <- function(directory = ".") { `_id` = NA_character_ ) - # Create media, see https://tdwg.github.io/camtrap-dp/data/#media + # Create media, see https://camtrap-dp.tdwg.org/data/#media media <- wi_images %>% dplyr::distinct(.data$location, .keep_all = TRUE) %>% @@ -317,7 +317,7 @@ read_wi <- function(directory = ".") { `_id` = NA_character_ ) - # Create observations, see https://tdwg.github.io/camtrap-dp/data/#observations + # Create observations, see https://camtrap-dp.tdwg.org/data/#observations observations <- wi_images %>% dplyr::transmute( diff --git a/R/write_dwc.R b/R/write_dwc.R index 5362de85..719b9763 100644 --- a/R/write_dwc.R +++ b/R/write_dwc.R @@ -1,7 +1,7 @@ #' Transform Camtrap DP data to Darwin Core #' #' Transforms data from a [Camera Trap Data Package]( -#' https://tdwg.github.io/camtrap-dp/) to [Darwin Core](https://dwc.tdwg.org/). +#' https://camtrap-dp.tdwg.org) to [Darwin Core](https://dwc.tdwg.org/). #' The resulting CSV files can be uploaded to an [IPT]( #' https://www.gbif.org/ipt) for publication to GBIF. #' A `meta.xml` file is included as well. diff --git a/R/write_eml.R b/R/write_eml.R index 8886a54a..bb2a1ad4 100644 --- a/R/write_eml.R +++ b/R/write_eml.R @@ -1,9 +1,9 @@ #' Transform Camtrap DP metadata to EML #' #' Transforms the metadata of a [Camera Trap Data Package]( -#' https://tdwg.github.io/camtrap-dp/) to an [EML]( -#' https://eml.ecoinformatics.org/) file that can be uploaded to a [GBIF IPT]( -#' https://www.gbif.org/ipt) for publication. +#' https://camtrap-dp.tdwg.org) to an [EML](https://eml.ecoinformatics.org/) +#' file that can be uploaded to a [GBIF IPT](https://www.gbif.org/ipt) for +#' publication. #' #' @param package A Camtrap DP, as read by [read_camtrap_dp()]. #' @param directory Path to local directory to write file to. diff --git a/README.Rmd b/README.Rmd index 9ed4514e..1e66eb6f 100644 --- a/README.Rmd +++ b/README.Rmd @@ -23,7 +23,7 @@ knitr::opts_chunk$set( ![last commit](https://img.shields.io/github/last-commit/inbo/camtraptor) -Camtraptor is an R package to read, explore and visualize Camera Trap Data Packages (Camtrap DP). [Camtrap DP](https://tdwg.github.io/camtrap-dp/) is a community developed data exchange format for this type of data. With camtraptor you can read and filter data, create overviews of observed species, relative abundance or effort, and plot these data on a map. +Camtraptor is an R package to read, explore and visualize Camera Trap Data Packages (Camtrap DP). [Camtrap DP](https://camtrap-dp.tdwg.org) is a community developed data exchange format for this type of data. With camtraptor you can read and filter data, create overviews of observed species, relative abundance or effort, and plot these data on a map. ## Camtrap DP diff --git a/README.md b/README.md index 7ed8f3b8..4f507202 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,10 @@ commit](https://img.shields.io/github/last-commit/inbo/camtraptor) Camtraptor is an R package to read, explore and visualize Camera Trap -Data Packages (Camtrap DP). [Camtrap -DP](https://tdwg.github.io/camtrap-dp/) is a community developed data -exchange format for this type of data. With camtraptor you can read and -filter data, create overviews of observed species, relative abundance or -effort, and plot these data on a map. +Data Packages (Camtrap DP). [Camtrap DP](https://camtrap-dp.tdwg.org) is +a community developed data exchange format for this type of data. With +camtraptor you can read and filter data, create overviews of observed +species, relative abundance or effort, and plot these data on a map. ## Camtrap DP diff --git a/man/map_dep.Rd b/man/map_dep.Rd index c8994adc..e0bff6b5 100644 --- a/man/map_dep.Rd +++ b/man/map_dep.Rd @@ -95,7 +95,7 @@ created internally by a \verb{get_*()} function). \item \code{longitude} } -See the \href{https://tdwg.github.io/camtrap-dp/data/#deployments}{Deployment} +See the \href{https://camtrap-dp.tdwg.org/data/#deployments}{Deployment} section of Camtrap DP for the full list of columns you can use.} \item{palette}{The palette name or the colour function that values will be diff --git a/man/mica.Rd b/man/mica.Rd index eeb64982..491bb09c 100644 --- a/man/mica.Rd +++ b/man/mica.Rd @@ -14,7 +14,7 @@ An object of class \code{datapackage} (inherits from \code{list}) of length 16. mica } \description{ -A sample \href{https://tdwg.github.io/camtrap-dp}{Camera Trap Data Package} as +A sample \href{https://camtrap-dp.tdwg.org}{Camera Trap Data Package} as read by \code{\link[=read_camtrap_dp]{read_camtrap_dp()}}. The source data are derived from the \href{https://github.com/tdwg/camtrap-dp/tree/ad0278ef86ef518dacfb306c598dce97667cfb81/example}{Camtrap DP example dataset} and are saved in \code{inst/extdata/mica}. diff --git a/man/read_camtrap_dp.Rd b/man/read_camtrap_dp.Rd index fea77426..6ce40786 100644 --- a/man/read_camtrap_dp.Rd +++ b/man/read_camtrap_dp.Rd @@ -26,7 +26,7 @@ as a property \code{data} containing the data as three data frames: } } \description{ -Reads files from a \href{https://tdwg.github.io/camtrap-dp}{Camera Trap Data Package} into memory. +Reads files from a \href{https://camtrap-dp.tdwg.org}{Camera Trap Data Package} into memory. All datetime information is automatically transformed to Coordinated Universal Time (UTC). Vernacular names found in the metadata (\code{package$taxonomic}) are added to the diff --git a/man/read_wi.Rd b/man/read_wi.Rd index 9fbbf544..1a16c3fe 100644 --- a/man/read_wi.Rd +++ b/man/read_wi.Rd @@ -19,7 +19,7 @@ Reads files from an unzipped \href{https://www.wildlifeinsights.org/}{Wildlife I Data can be exported from Wildlife Insights as a \href{https://www.wildlifeinsights.org/get-started/data-download/public}{public} or \href{https://www.wildlifeinsights.org/get-started/download/private}{private} download. -The function transforms data and metadata to a \href{https://tdwg.github.io/camtrap-dp}{Camera Trap Data Package} which can be written to file with +The function transforms data and metadata to a \href{https://camtrap-dp.tdwg.org}{Camera Trap Data Package} which can be written to file with \code{\link[frictionless:write_package]{frictionless::write_package()}}. } \details{ diff --git a/man/write_dwc.Rd b/man/write_dwc.Rd index b2f8971c..843d8f20 100644 --- a/man/write_dwc.Rd +++ b/man/write_dwc.Rd @@ -19,7 +19,7 @@ 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}. +Transforms data from a \href{https://camtrap-dp.tdwg.org}{Camera Trap Data Package} to \href{https://dwc.tdwg.org/}{Darwin Core}. 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. diff --git a/man/write_eml.Rd b/man/write_eml.Rd index f946b71c..4956fa57 100644 --- a/man/write_eml.Rd +++ b/man/write_eml.Rd @@ -45,7 +45,9 @@ name. \code{directory = NULL}. } \description{ -Transforms the metadata of a \href{https://tdwg.github.io/camtrap-dp/}{Camera Trap Data Package} to an \href{https://eml.ecoinformatics.org/}{EML} file that can be uploaded to a \href{https://www.gbif.org/ipt}{GBIF IPT} for publication. +Transforms the metadata of a \href{https://camtrap-dp.tdwg.org}{Camera Trap Data Package} to an \href{https://eml.ecoinformatics.org/}{EML} +file that can be uploaded to a \href{https://www.gbif.org/ipt}{GBIF IPT} for +publication. } \section{Transformation details}{ From 48d5d716cd1e670c2ad38573176b41696a6cc35e Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Wed, 8 Nov 2023 10:27:26 +0100 Subject: [PATCH 31/39] Update supported versions message --- R/read_camtrap_dp.R | 11 ++++------- tests/testthat/test-read_camtrap_dp.R | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/R/read_camtrap_dp.R b/R/read_camtrap_dp.R index 6fcd5ec3..7817918f 100644 --- a/R/read_camtrap_dp.R +++ b/R/read_camtrap_dp.R @@ -97,13 +97,10 @@ read_camtrap_dp <- function(file = NULL, # check version is supported assertthat::assert_that( version %in% supported_versions, - msg = paste0( - glue::glue("Version {version} "), - "is not supported. Supported versions: ", - glue::glue_collapse(glue::glue("{supported_versions}"), - sep = " ", - last = " and "), - ".") + msg = glue::glue( + "Version `{version}` is not supported. Supported versions: ", + glue::glue_collapse(supported_versions, sep = " ", last = " and ") + ) ) # get resource names diff --git a/tests/testthat/test-read_camtrap_dp.R b/tests/testthat/test-read_camtrap_dp.R index 05c38ea9..6fd31bd6 100644 --- a/tests/testthat/test-read_camtrap_dp.R +++ b/tests/testthat/test-read_camtrap_dp.R @@ -31,13 +31,13 @@ test_that("file can be an URL", { test_that("only DP versions 1.0 and dp 0.1.6 are supported", { expect_error( 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.", + "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", fixed = TRUE ) expect_error( 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", + "Version `tabular-data-package` is not supported. Supported versions: 0.1.6 and 1.0", fixed = TRUE ) }) From b149c321d3a36878bbbf0dcfc9bbb29c2ddc358a Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Wed, 8 Nov 2023 10:27:44 +0100 Subject: [PATCH 32/39] Change taxonID to character --- R/zzz.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/zzz.R b/R/zzz.R index d8e694dd..15866f38 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -850,7 +850,7 @@ convert_observations_to_0.1.6 <- function(package, from = "1.0") { # add taxonID if missing if(!"taxonID" %in% colnames(observations)){ observations <- observations %>% - dplyr::mutate(taxonID = NA_integer_) + dplyr::mutate(taxonID = NA_character_) } # add taxonIDReference if missing if(!"taxonIDReference" %in% colnames(observations)){ From ee4cea485fdbb5c317985004186cbb8ad8d5ddf5 Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Wed, 8 Nov 2023 11:25:54 +0100 Subject: [PATCH 33/39] Simplify glue in messages --- R/zzz.R | 84 +++++++++++++++++++++++---------------------------------- 1 file changed, 34 insertions(+), 50 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 15866f38..0aba19a6 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -445,12 +445,10 @@ convert_to_0.1.6 <- function(package, from = "1.0", media = TRUE){ supported_versions <- c("1.0") assertthat::assert_that( from %in% supported_versions, - msg = paste0( + msg = glue::glue( "Only conversion from ", - glue::glue_collapse(glue::glue("{supported_versions}"), - sep = " ", - last = " and "), - " to 0.1.6 is supported." + glue::glue_collapse(supported_versions, sep = " ", last = " and "), + " to `0.1.6` is supported." ) ) # check data slot is present in package @@ -460,12 +458,10 @@ convert_to_0.1.6 <- function(package, from = "1.0", media = TRUE){ ) # notify about conversion - message(paste0( - collapse = "\n", - c( - "The dataset uses Camtrap DP version 1.0, it has been converted to 0.1.6.", - "See https://inbo.github.io/camtraptor/#camtrap-dp for details." - ) + message(glue::glue( + "The dataset uses Camtrap DP version 1.0, it has been converted to 0.1.6.", + "See https://inbo.github.io/camtraptor/#camtrap-dp for details.", + .sep = "\n" )) # convert metadata package <- convert_metadata_to_0.1.6(package, from) @@ -496,38 +492,28 @@ convert_metadata_to_0.1.6 <- function(package, from = "1.0"){ if ("role" %in% names(authors)) { deprecated_roles <- c("author", "maintainer") if (any(deprecated_roles %in% authors$role)) { - warning(paste0( + warning(glue::glue( "Roles ", - glue::glue_collapse(glue::glue("{deprecated_roles}"), - sep = " ", - last = " and "), - " are deprecated in ", - "version {from}." - ) - ) + glue::glue_collapse(deprecated_roles, sep = " ", last = " and "), + " are deprecated in version {from}." + )) } } if ("organizations" %in% names(package)) { warning(glue::glue( - "The field `organizations` is deprecated in ", - "version {from}." - ) - ) + "The field `organizations` is deprecated in version {from}." + )) } if ("animalTypes" %in% names(package)) { warning(glue::glue( - "The field `animalTypes` is deprecated in", - "version {from}." - ) - ) + "The field `animalTypes` is deprecated in version {from}." + )) } names(package)[names(package) == "observationLevel"] <- "classificationLevel" if ("sequenceInterval" %in% names(package$project)) { warning(glue::glue( - "The field `sequenceInterval` is deprecated in", - "version {from}." - ) - ) + "The field `sequenceInterval` is deprecated in version {from}." + )) } package$platform <- package$sources[[1]]$title # `title` value of the first contributor with role `rightsHolder` @@ -613,9 +599,9 @@ convert_deployments_to_0.1.6 <- function(package, from = "1.0") { dplyr::mutate(baitUse = factor(.data$baitUse, levels = bait_uses_old)) } if ("session" %in% names(deployments)) { - warning(glue::glue("The field `session` of deployments is deprecated in", - "version {from}.") - ) + warning(glue::glue( + "The field `session` of deployments is deprecated in version {from}." + )) } else { deployments <- deployments %>% dplyr::mutate(session = NA) @@ -637,17 +623,17 @@ convert_deployments_to_0.1.6 <- function(package, from = "1.0") { dplyr::select(-"deploymentGroups") } if ("array" %in% names(deployments)) { - warning(glue::glue("The field `array` of deployments is deprecated in", - "version {from}.") - ) + warning(glue::glue( + "The field `array` of deployments is deprecated in version {from}." + )) } else { deployments <- deployments %>% dplyr::mutate(array = NA) } if ("_id" %in% names(deployments)) { - warning(glue::glue("The field `_id` of deployments is deprecated in", - "version {from}.") - ) + warning(glue::glue( + "The field `_id` of deployments is deprecated in version {from}." + )) } else { deployments <- deployments %>% dplyr::mutate("_id" = NA) @@ -727,9 +713,9 @@ convert_media_to_0.1.6 <- function(package, from = "1.0") { dplyr::rename(comments = "mediaComments") } if ("_id" %in% names(media)) { - warning(glue::glue("The field `_id` of media is deprecated in", - "version {from}.") - ) + warning(glue::glue( + "The field `_id` of media is deprecated in version {from}." + )) } else { media <- media %>% dplyr::mutate("_id" = NA) @@ -798,10 +784,8 @@ convert_observations_to_0.1.6 <- function(package, from = "1.0") { } if ("countNew" %in% names(observations)) { warning(glue::glue( - "The field `countNew` of observations is deprecated in", - "version {from}." - ) - ) + "The field `countNew` of observations is deprecated in version {from}." + )) } else { observations <- observations %>% dplyr::mutate("countNew" = NA) @@ -826,9 +810,9 @@ convert_observations_to_0.1.6 <- function(package, from = "1.0") { dplyr::rename(comments = "observationComments") } if ("_id" %in% names(observations)) { - warning(glue::glue("The field `_id` of observations is deprecated in", - "version {from}.") - ) + warning(glue::glue( + "The field `_id` of observations is deprecated in version {from}." + )) } else { observations <- observations %>% dplyr::mutate("_id" = NA) From 1c7711604f1c5f12d0fb2983c763eac63cb082b6 Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Wed, 8 Nov 2023 12:12:04 +0100 Subject: [PATCH 34/39] Simplify check_value(), don't use custom transformer Use glue::glue_collapse() over custom transformer() --- R/calc_animal_pos.R | 7 +- R/check_package.R | 4 +- R/get_n_individuals.R | 5 +- R/get_n_obs.R | 5 +- R/map_dep.R | 4 +- R/zzz.R | 46 ++++------- tests/testthat/test-check_species.R | 19 +++-- tests/testthat/test-get_cam_op.R | 6 +- tests/testthat/test-get_custom_effort.R | 104 ++++++++++++++---------- tests/testthat/test-get_effort.R | 17 ++-- tests/testthat/test-map_dep.R | 11 ++- 11 files changed, 118 insertions(+), 110 deletions(-) diff --git a/R/calc_animal_pos.R b/R/calc_animal_pos.R index b0aa577a..61502087 100644 --- a/R/calc_animal_pos.R +++ b/R/calc_animal_pos.R @@ -51,8 +51,11 @@ calc_animal_pos <- function(animal_pos, assertthat::assert_that( length(not_found_cols) == 0, msg = glue::glue( - "Columns `{not_found_cols}` not found in `animal_pos`.", - .transformer = collapse_transformer(sep = "`, `", last = "` and `") + "Columns ", + glue::glue_collapse( + glue::backtick(not_found_cols), sep = ", ", last = " and " + ), + " not found in `animal_pos`." ) ) diff --git a/R/check_package.R b/R/check_package.R index aeebf8e8..223878eb 100644 --- a/R/check_package.R +++ b/R/check_package.R @@ -52,8 +52,8 @@ check_package <- function(package = NULL, assertthat::assert_that( length(tables_absent) == 0, msg = glue::glue( - "Can't find {length(tables_absent)} elements in data package: {tables_absent*}", - .transformer = collapse_transformer(sep = ", ", last = " and ") + "Can't find {length(tables_absent)} elements in data package: ", + glue::glue_collapse(tables_absent, sep = ", ", last = " and ") ) ) if (media) { diff --git a/R/get_n_individuals.R b/R/get_n_individuals.R index d982dfe1..4fd24258 100644 --- a/R/get_n_individuals.R +++ b/R/get_n_individuals.R @@ -87,9 +87,8 @@ get_n_individuals <- function(package = NULL, if (length(species) > 1) { ignored_species <- species[!species == "all"] warning(glue::glue( - "Value `all` found in `species`.", - "All other values are ignored: {ignored_species*}.", - .transformer = collapse_transformer(sep = ", ", last = " and ") + "Value `all` found in `species`. All other values are ignored: ", + glue::glue_collapse(ignored_species, sep = ", ", last = " and ") )) } species <- get_species(package)$scientificName diff --git a/R/get_n_obs.R b/R/get_n_obs.R index 8d3187f7..e94f0613 100644 --- a/R/get_n_obs.R +++ b/R/get_n_obs.R @@ -84,9 +84,8 @@ get_n_obs <- function(package = NULL, if (length(species) > 1) { ignored_species <- species[!species == "all"] warning(glue::glue( - "Value `all` found in `species`.", - "All other values are ignored: {ignored_species*}.", - .transformer = collapse_transformer(sep = ", ", last = " and ") + "Value `all` found in `species`. All other values are ignored: ", + glue::glue_collapse(ignored_species, sep = ", ", last = " and ") )) } species <- get_species(package)$scientificName diff --git a/R/map_dep.R b/R/map_dep.R index 7efbf19a..6b3548c0 100644 --- a/R/map_dep.R +++ b/R/map_dep.R @@ -545,8 +545,8 @@ map_dep <- function(package = NULL, if (n_not_found_cols > 0) { warning(glue::glue( "Can't find {n_not_found_cols} columns defined in `hover_columns` in ", - "deployments: {not_found_cols*}", - .transformer = collapse_transformer(sep = ", ", last = " and ") + "deployments: ", + glue::glue_collapse(not_found_col, sep = ", ", last = " and ") )) } } diff --git a/R/zzz.R b/R/zzz.R index 0aba19a6..d4d3f075 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -37,26 +37,24 @@ check_value <- function(arg, options = NULL, arg_name, null_allowed = TRUE) { # Suppress long messages with valid options if (length(options) > max_print) { - options_to_print <- c(options[1:max_print], "others..") + options_to_print <- c(options[1:max_print], "others...") } else { options_to_print <- options } - - # compose error message - if (null_allowed == TRUE) { - string_to_print <- "Invalid value for {arg_name} parameter: {wrong_values}. - Valid inputs are: NULL, {options_to_print*}." - } else { - if (is.null(wrong_values)) { - wrong_values <- "NULL" - } - string_to_print <- "Invalid value for {arg_name} parameter: {wrong_values}. - Valid inputs are: {options_to_print*}." + + # Include NULL + if (null_allowed) { + options_to_print <- append(options_to_print, "NULL") + } else if (is.null(wrong_values)) { + wrong_values <- "NULL" } - + + # Compose error message msg_to_print <- glue::glue( - string_to_print, - .transformer = collapse_transformer(sep = ", ", last = " and ") + "Invalid value for {arg_name} parameter: ", + glue::glue_collapse(wrong_values, sep = ", ", last = " and "), + ".\nValid inputs are: ", + glue::glue_collapse(options_to_print, sep = ", ", last = " and ") ) # Provide user message @@ -72,21 +70,6 @@ check_value <- function(arg, options = NULL, arg_name, null_allowed = TRUE) { } } -#' Print list of options -#' -#' @param regex Character. A regular expression to parse. -#' @param ... Additional parameters passed to the collapse. -#' @noRd -collapse_transformer <- function(regex = "[*]$", ...) { - function(code, envir) { - if (grepl(regex, code)) { - code <- sub(regex, "", code) - } - res <- eval(parse(text = code), envir) - glue::glue_collapse(res, ...) - } -} - #' Check reading issues #' #' This helper function throws a warning if issues while reading datapackage @@ -207,8 +190,7 @@ get_dep_no_obs <- function(package = NULL, } message(glue::glue( "There are {n_dep_no_obs} deployments without observations: ", - "{options_to_print*}", - .transformer = collapse_transformer(sep = ", ", last = " and ") + glue::glue_collapse(options_to_print, sep = ", ", last = " and ") )) } return(dep_no_obs) diff --git a/tests/testthat/test-check_species.R b/tests/testthat/test-check_species.R index 74bff7d1..e60681c6 100644 --- a/tests/testthat/test-check_species.R +++ b/tests/testthat/test-check_species.R @@ -12,17 +12,18 @@ test_that("Error is returned if one or more species are invalid", { "Ans streperi", # wrong "blauwe reiger", "Anas strepera", - "bad name" + "bad name" # wrong ) - ), # wrong - paste( - "Invalid value for species parameter: ans streperi and bad", - "name.\nValid inputs are: anas platyrhynchos, anas strepera, ardea,", - "ardea cinerea, castor fiber, homo sapiens, martes foina, mustela", - "putorius, vulpes vulpes, mallard, gadwall, great herons, grey", - "heron, eurasian beaver, human, beech marten, european polecat, red", - "fox, wilde eend, krakeend and others..." ), + paste0( + "Invalid value for species parameter: ans streperi and bad name.\n", + "Valid inputs are: anas platyrhynchos, anas strepera, ardea, ardea ", + "cinerea, castor fiber, homo sapiens, martes foina, mustela putorius, ", + "vulpes vulpes, mallard, gadwall, great herons, grey heron, eurasian ", + "beaver, human, beech marten, european polecat, red fox, wilde eend, ", + "krakeend and others..." + ), + fixed = TRUE ) }) diff --git a/tests/testthat/test-get_cam_op.R b/tests/testthat/test-get_cam_op.R index e5726572..976d4d09 100644 --- a/tests/testthat/test-get_cam_op.R +++ b/tests/testthat/test-get_cam_op.R @@ -16,8 +16,10 @@ test_that("input camtrap dp is checked properly", { # station_col value is not a column of deployments expect_error( get_cam_op(mica, station_col = "bla"), - regexp = paste("Station column name (`bla`) is not valid:", - "it must be one of the deployments column names."), + paste0( + "Station column name (`bla`) is not valid: ", + "it must be one of the deployments column names." + ), fixed = TRUE ) # column specified by station_col contains empty values diff --git a/tests/testthat/test-get_custom_effort.R b/tests/testthat/test-get_custom_effort.R index 44ebff35..f4b3fb9c 100644 --- a/tests/testthat/test-get_custom_effort.R +++ b/tests/testthat/test-get_custom_effort.R @@ -1,10 +1,11 @@ test_that("get_custom_effort returns error for invalid group_by value", { - expect_error(get_custom_effort(mica, group_by = "bad_value"), - regexp = paste0("Invalid value for group_by parameter: ", - "bad_value.\n", - "Valid inputs are: NULL, day, week, month ", - "and year."), - fixed = TRUE + expect_error( + get_custom_effort(mica, group_by = "bad_value"), + paste0( + "Invalid value for group_by parameter: bad_value.\n", + "Valid inputs are: day, week, month, year and NULL" + ), + fixed = TRUE ) }) @@ -14,10 +15,12 @@ test_that("get_custom_effort returns error for start not a Date", { expect_error( get_custom_effort( mica, - start = lubridate::as_datetime("2021-12-05 22:25:01 CET")), - regexp = paste0("`start` must be `NULL` or an object of class Date. ", - "Did you forget to convert a string to Date with ", - "`as.Date()`?"), + start = lubridate::as_datetime("2021-12-05 22:25:01 CET") + ), + paste0( + "`start` must be `NULL` or an object of class Date. ", + "Did you forget to convert a string to Date with `as.Date()`?" + ), fixed = TRUE ) }) @@ -26,60 +29,73 @@ test_that("get_custom_effort returns error for end not a Date", { expect_error(get_custom_effort(mica, end = "2021-01-01")) # No datetime allowed expect_error( - get_custom_effort(mica, - end = lubridate::as_datetime("2021-12-05 22:25:01 CET")), - regexp = paste0("`end` must be `NULL` or an object of class Date. ", - "Did you forget to convert a string to Date with ", - "`as.Date()`?"), + get_custom_effort( + mica, + end = lubridate::as_datetime("2021-12-05 22:25:01 CET") + ), + paste0( + "`end` must be `NULL` or an object of class Date. ", + "Did you forget to convert a string to Date with `as.Date()`?" + ), fixed = TRUE ) }) test_that("get_custom_effort returns error if end earlier than start", { expect_error( - get_custom_effort(mica, - start = as.Date("2021-01-01"), - end = as.Date("1990-01-01")), - regexp = paste0("`end` value is set too early. `end` value must be not ", - "earlier than the start of the earliest deployment: ", - "2019-10-09."), + get_custom_effort( + mica, start = as.Date("2021-01-01"), end = as.Date("1990-01-01") + ), + paste0( + "`end` value is set too early. `end` value must be not earlier than the ", + "start of the earliest deployment: 2019-10-09." + ), fixed = TRUE ) }) test_that( "get_custom_effort returns error if start later than end of latest deployment", { - expect_error(get_custom_effort(mica, start = as.Date("2030-01-01")), - regexp = paste0( - "`start` value is set too late. ", - "`start` value must be not later than the end of the latest ", - "deployment: 2021-04-18." - ), - fixed = TRUE - ) + expect_error( + get_custom_effort(mica, start = as.Date("2030-01-01")), + paste0( + "`start` value is set too late. ", + "`start` value must be not later than the end of the latest deployment: ", + "2021-04-18." + ), + fixed = TRUE + ) }) test_that( "get_custom_effort returns error if end earlier than begin of first deployment", { - expect_error(get_custom_effort(mica, end = as.Date("1900-04-05")), - regexp = paste0( - "`end` value is set too early. ", - "`end` value must be not earlier than the start of the ", - "earliest deployment: 2019-10-09."), - fixed = TRUE + expect_error( + get_custom_effort(mica, end = as.Date("1900-04-05")), + paste0( + "`end` value is set too early. ", + "`end` value must be not earlier than the start of the ", + "earliest deployment: 2019-10-09." + ), + fixed = TRUE ) }) test_that("get_custom_effort returns error for invalid effort units", { - expect_error(get_custom_effort(mica, unit = "second"), - regexp = paste0("Invalid value for unit parameter: second.\n", - "Valid inputs are: hour and day."), - fixed = TRUE - ) - expect_error(get_custom_effort(mica, unit = "year"), - regexp = paste0("Invalid value for unit parameter: year.\n", - "Valid inputs are: hour and day."), - fixed = TRUE + expect_error( + get_custom_effort(mica, unit = "second"), + paste0( + "Invalid value for unit parameter: second.\n", + "Valid inputs are: hour and day" + ), + fixed = TRUE + ) + expect_error( + get_custom_effort(mica, unit = "year"), + paste0( + "Invalid value for unit parameter: year.\n", + "Valid inputs are: hour and day" + ), + fixed = TRUE ) }) diff --git a/tests/testthat/test-get_effort.R b/tests/testthat/test-get_effort.R index 1df1a113..7ae13b43 100644 --- a/tests/testthat/test-get_effort.R +++ b/tests/testthat/test-get_effort.R @@ -1,12 +1,20 @@ testthat::test_that("get_effort returns error for invalid effort units", { testthat::expect_error( get_effort(mica, unit = "bad_unit"), - "Invalid value for unit parameter: bad_unit. -Valid inputs are: second, minute, hour, day, month and year.") + paste0( + "Invalid value for unit parameter: bad_unit.\n", + "Valid inputs are: second, minute, hour, day, month and year" + ), + fixed = TRUE + ) testthat::expect_error( get_effort(mica, unit = NULL), - "Invalid value for unit parameter: NULL. -Valid inputs are: second, minute, hour, day, month and year.") + paste0( + "Invalid value for unit parameter: NULL.\n", + "Valid inputs are: second, minute, hour, day, month and year" + ), + fixed = TRUE + ) }) testthat::test_that("get_effort returns error for invalid datapackage", { @@ -85,4 +93,3 @@ test_that("Argument datapkg is deprecated: warning returned", { 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-map_dep.R b/tests/testthat/test-map_dep.R index f882984e..cf92cc4c 100644 --- a/tests/testthat/test-map_dep.R +++ b/tests/testthat/test-map_dep.R @@ -15,15 +15,14 @@ test_that("map_dep() returns error for invalid feature", { "rai_individuals", "effort" ) - valid_input_string <- - sub(",([^,]*)$", " and\\1", paste(valid_inputs, collapse = ", ")) - no_feature <- "not a feature" + no_feature <- "not_a_feature" # invalid feature expect_error( map_dep(mica, feature = no_feature), - regexp = glue::glue("Invalid value for feature parameter: {no_feature}.", - "Valid inputs are: {valid_input_string}.", - .sep = "\n" + paste0( + "Invalid value for feature parameter: not_a_feature.\n", + "Valid inputs are: n_species, n_obs, n_individuals, rai, ", + "rai_individuals and effort" ), fixed = TRUE ) From 868c307e15bfbe8934d29f16de751ea2ed7edc88 Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Wed, 8 Nov 2023 12:12:34 +0100 Subject: [PATCH 35/39] Don't name regexp parameter --- tests/testthat/test-check_package.R | 20 ++++----- tests/testthat/test-get_cam_op.R | 6 +-- tests/testthat/test-get_custom_effort.R | 2 +- tests/testthat/test-get_effort.R | 3 +- tests/testthat/test-get_n_individuals.R | 2 +- tests/testthat/test-get_n_obs.R | 2 +- tests/testthat/test-get_n_species.R | 2 +- tests/testthat/test-get_rai.R | 4 +- tests/testthat/test-get_rai_individuals.R | 2 +- tests/testthat/test-get_record_table.R | 2 +- tests/testthat/test-get_scientific_name.R | 2 +- tests/testthat/test-get_species.R | 2 +- tests/testthat/test-map_dep.R | 54 +++++++++++------------ tests/testthat/test-write_eml.R | 18 +++++--- 14 files changed, 62 insertions(+), 59 deletions(-) diff --git a/tests/testthat/test-check_package.R b/tests/testthat/test-check_package.R index 16116c48..9a12895f 100644 --- a/tests/testthat/test-check_package.R +++ b/tests/testthat/test-check_package.R @@ -1,7 +1,7 @@ test_that("check_package() returns deprecation 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.", + "The `datapkg` argument of `function_name_here()` is deprecated as of camtraptor 0.16.0.", fixed = TRUE ) }) @@ -9,13 +9,13 @@ test_that("check_package() returns deprecation 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.", + "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.", + "package is not a list.", fixed = TRUE ) }) @@ -23,7 +23,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")), - regexp = "data element is missing from package", + "data element is missing from package", fixed = TRUE ) }) @@ -33,14 +33,14 @@ test_that("check_package() returns error if not all elements are present", { mica_no_dep$data$deployments <- NULL expect_error( check_package(mica_no_dep, media = TRUE), - regexp = "Can't find 1 elements in data package: deployments", + "Can't find 1 elements in data package: deployments", fixed = TRUE ) mica_no_dep_no_obs <- mica_no_dep mica_no_dep_no_obs$data$observations <- NULL expect_error( check_package(mica_no_dep_no_obs), - regexp = "Can't find 2 elements in data package: deployments and observations", + "Can't find 2 elements in data package: deployments and observations", fixed = TRUE ) }) @@ -51,7 +51,7 @@ test_that( 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", + "Can't find 1 elements in data package: media", fixed = TRUE ) expect_true(check_package(mica_no_media)) @@ -62,7 +62,7 @@ test_that("check_package() returns error if observations is not a data.frame", { 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", + "package$data$observations is not a data frame", fixed = TRUE ) }) @@ -72,7 +72,7 @@ test_that("check_package() returns error if deployments is not a data.frame", { 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", + "package$data$deployments is not a data frame", fixed = TRUE ) }) @@ -89,7 +89,7 @@ test_that("check_package() returns error if media is not a data.frame", { 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", + "package$data$media is not a data frame", fixed = TRUE ) }) diff --git a/tests/testthat/test-get_cam_op.R b/tests/testthat/test-get_cam_op.R index 976d4d09..60dda148 100644 --- a/tests/testthat/test-get_cam_op.R +++ b/tests/testthat/test-get_cam_op.R @@ -6,12 +6,12 @@ test_that("input camtrap dp is checked properly", { # station_col is not NA expect_error( get_cam_op(mica, station_col = NA), - regexp = "station_col is not a string (a length one character vector).", + "station_col is not a string (a length one character vector).", fixed = TRUE) # station_col is length 1 expect_error( get_cam_op(mica, station_col = c("locationID","locationName")), - regexp = "station_col is not a string (a length one character vector).", + "station_col is not a string (a length one character vector).", fixed = TRUE) # station_col value is not a column of deployments expect_error( @@ -175,7 +175,7 @@ test_that("Argument datapkg is deprecated: warning returned", { lifecycle_verbosity = "warning", get_cam_op(datapkg = mica) ), - regexp = "The `datapkg` argument of `get_cam_op()` is deprecated as of camtraptor 0.16.0.", + "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 f4b3fb9c..fe073958 100644 --- a/tests/testthat/test-get_custom_effort.R +++ b/tests/testthat/test-get_custom_effort.R @@ -254,7 +254,7 @@ test_that("Argument datapkg is deprecated: warning returned", { lifecycle_verbosity = "warning", get_custom_effort(datapkg = mica) ), - regexp = "The `datapkg` argument of `get_custom_effort()` is deprecated as of camtraptor 0.16.0.", + "The `datapkg` argument of `get_custom_effort()` is deprecated as of camtraptor 0.16.0.", fixed = TRUE ) }) diff --git a/tests/testthat/test-get_effort.R b/tests/testthat/test-get_effort.R index 7ae13b43..86de9ad1 100644 --- a/tests/testthat/test-get_effort.R +++ b/tests/testthat/test-get_effort.R @@ -90,6 +90,7 @@ test_that("Argument datapkg is deprecated: warning returned", { lifecycle_verbosity = "warning", get_effort(datapkg = mica) ), - regexp = "The `datapkg` argument of `get_effort()` is deprecated as of camtraptor 0.16.0.", + "The `datapkg` argument of `get_effort()` is deprecated as of camtraptor 0.16.0.", fixed = TRUE ) +}) diff --git a/tests/testthat/test-get_n_individuals.R b/tests/testthat/test-get_n_individuals.R index c2ff521e..79ba8cc9 100644 --- a/tests/testthat/test-get_n_individuals.R +++ b/tests/testthat/test-get_n_individuals.R @@ -254,7 +254,7 @@ test_that("Argument datapkg is deprecated: warning returned", { lifecycle_verbosity = "warning", get_n_individuals(datapkg = mica) ), - regexp = "The `datapkg` argument of `get_n_individuals()` is deprecated as of camtraptor 0.16.0.", + "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 0b4befd3..a761490f 100644 --- a/tests/testthat/test-get_n_obs.R +++ b/tests/testthat/test-get_n_obs.R @@ -287,7 +287,7 @@ test_that("Argument datapkg is deprecated: warning returned", { lifecycle_verbosity = "warning", get_n_obs(datapkg = mica) ), - regexp = "The `datapkg` argument of `get_n_obs()` is deprecated as of camtraptor 0.16.0.", + "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 19c27ef3..8aa5bc29 100644 --- a/tests/testthat/test-get_n_species.R +++ b/tests/testthat/test-get_n_species.R @@ -51,7 +51,7 @@ test_that("Argument datapkg is deprecated: warning returned", { lifecycle_verbosity = "warning", get_n_species(datapkg = mica) ), - regexp = "The `datapkg` argument of `get_n_species()` is deprecated as of camtraptor 0.16.0.", + "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 dd3056df..678b85d0 100644 --- a/tests/testthat/test-get_rai.R +++ b/tests/testthat/test-get_rai.R @@ -111,7 +111,7 @@ test_that("Argument datapkg is deprecated: warning returned", { lifecycle_verbosity = "warning", get_rai(datapkg = mica) ), - regexp = "The `datapkg` argument of `get_rai()` is deprecated as of camtraptor 0.16.0.", + "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 0d59c2f8..c625370a 100644 --- a/tests/testthat/test-get_rai_individuals.R +++ b/tests/testthat/test-get_rai_individuals.R @@ -115,7 +115,7 @@ test_that("Argument datapkg is deprecated: warning returned", { lifecycle_verbosity = "warning", get_rai_individuals(datapkg = mica) ), - regexp = "The `datapkg` argument of `get_rai_individuals()` is deprecated as of camtraptor 0.16.0.", + "The `datapkg` argument of `get_rai_individuals()` is deprecated as of camtraptor 0.16.0.", fixed = TRUE ) }) diff --git a/tests/testthat/test-get_record_table.R b/tests/testthat/test-get_record_table.R index 79772aa7..9e0193f8 100644 --- a/tests/testthat/test-get_record_table.R +++ b/tests/testthat/test-get_record_table.R @@ -201,7 +201,7 @@ test_that("Argument datapkg is deprecated: warning returned", { lifecycle_verbosity = "warning", get_record_table(datapkg = mica) ), - regexp = "The `datapkg` argument of `get_record_table()` is deprecated as of camtraptor 0.16.0.", + "The `datapkg` argument of `get_record_table()` is deprecated as of camtraptor 0.16.0.", fixed = TRUE ) }) diff --git a/tests/testthat/test-get_scientific_name.R b/tests/testthat/test-get_scientific_name.R index 415ad934..36b939f4 100644 --- a/tests/testthat/test-get_scientific_name.R +++ b/tests/testthat/test-get_scientific_name.R @@ -25,7 +25,7 @@ test_that("Argument datapkg is deprecated: warning returned", { 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.", + "The `datapkg` argument of `get_scientific_name()` is deprecated as of camtraptor 0.16.0.", fixed = TRUE ) }) diff --git a/tests/testthat/test-get_species.R b/tests/testthat/test-get_species.R index fcfb0408..17cbf7e5 100644 --- a/tests/testthat/test-get_species.R +++ b/tests/testthat/test-get_species.R @@ -78,7 +78,7 @@ test_that("Argument datapkg is deprecated: warning returned", { lifecycle_verbosity = "warning", get_species(datapkg = mica) ), - regexp = "The `datapkg` argument of `get_species()` is deprecated as of camtraptor 0.16.0.", + "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 cf92cc4c..9f8f1cd3 100644 --- a/tests/testthat/test-map_dep.R +++ b/tests/testthat/test-map_dep.R @@ -1,6 +1,6 @@ test_that("map_dep() returns error when feature is missing", { expect_error(map_dep(mica), - regexp = 'argument "feature" is missing, with no default', + 'argument "feature" is missing, with no default', fixed = TRUE ) }) @@ -29,7 +29,7 @@ test_that("map_dep() returns error for invalid feature", { # more than one feature expect_error( map_dep(mica, feature = valid_inputs[1:2]), - regexp = "`feature` must have length 1", + "`feature` must have length 1", fixed = TRUE ) }) @@ -37,17 +37,17 @@ test_that("map_dep() returns error for invalid feature", { test_that("map_dep() can handle combinations of arguments", { expect_warning( map_dep(mica, feature = "n_species", effort_unit = "month"), - regexp = "`effort_unit` ignored for `feature = n_species`.", + "`effort_unit` ignored for `feature = n_species`.", fixed = TRUE ) expect_warning( map_dep(mica, feature = "n_species", sex = "male"), - regexp = "`sex` ignored for `feature = n_species`.", + "`sex` ignored for `feature = n_species`.", fixed = TRUE ) expect_warning( map_dep(mica, feature = "n_species", life_stage = "subadult"), - regexp = "`life_stage` ignored for `feature = n_species`.", + "`life_stage` ignored for `feature = n_species`.", fixed = TRUE ) }) @@ -56,31 +56,31 @@ test_that("map_dep() can toggle showing deployments with zero values", { # expect an error when the toggle has length > 1 expect_error(map_dep(mica, feature = "n_obs", zero_values_show = c(TRUE, TRUE)), - regexp = "zero_values_show must be a logical: TRUE or FALSE.", + "zero_values_show must be a logical: TRUE or FALSE.", fixed = TRUE) # expect an error when the toggle is not TRUE or FALSE expect_error(map_dep(mica, feature = "n_obs", zero_values_show = "dax"), - regexp = "zero_values_show must be a logical: TRUE or FALSE.", + "zero_values_show must be a logical: TRUE or FALSE.", fixed = TRUE) expect_error(map_dep(mica, feature = "n_obs", zero_values_show = NA), - regexp = "zero_values_show must be a logical: TRUE or FALSE.", + "zero_values_show must be a logical: TRUE or FALSE.", fixed = TRUE) expect_error(map_dep(mica, feature = "n_obs", zero_values_show = NULL), - regexp = "zero_values_show must be a logical: TRUE or FALSE.", + "zero_values_show must be a logical: TRUE or FALSE.", fixed = TRUE) # expect a message when an url/size is provided but the toggle is off suppressMessages(expect_message( map_dep(mica, feature = "n_obs", zero_values_show = FALSE), - regexp = "`zero_values_show` is FALSE: `zero_values_icon_url` ignored.", + "`zero_values_show` is FALSE: `zero_values_icon_url` ignored.", fixed = TRUE )) suppressMessages(expect_message( map_dep(mica, feature = "n_obs", zero_values_show = FALSE), - regexp = "`zero_values_show` is FALSE: `zero_values_icon_size` is ignored.", + "`zero_values_show` is FALSE: `zero_values_icon_size` is ignored.", fixed = TRUE )) @@ -93,31 +93,31 @@ test_that("map_dep() can toggle showing deployments with NA values", { # expect an error when the toggle has length > 1 expect_error(map_dep(mica, feature = "n_obs", na_values_show = c(TRUE, TRUE)), - regexp = "na_values_show must be a logical: TRUE or FALSE.", + "na_values_show must be a logical: TRUE or FALSE.", fixed = TRUE) # expect an error when the toggle is not TRUE or FALSE expect_error(map_dep(mica, feature = "n_obs", na_values_show = "dax"), - regexp = "na_values_show must be a logical: TRUE or FALSE.", + "na_values_show must be a logical: TRUE or FALSE.", fixed = TRUE) expect_error(map_dep(mica, feature = "n_obs", na_values_show = NA), - regexp = "na_values_show must be a logical: TRUE or FALSE.", + "na_values_show must be a logical: TRUE or FALSE.", fixed = TRUE) expect_error(map_dep(mica, feature = "n_obs", na_values_show = NULL), - regexp = "na_values_show must be a logical: TRUE or FALSE.", + "na_values_show must be a logical: TRUE or FALSE.", fixed = TRUE) # expect a message when an url/size is provided but the toggle is off suppressMessages(expect_message( map_dep(mica, feature = "n_obs", na_values_show = FALSE), - regexp = "`na_values_show` is FALSE: `na_values_icon_url` ignored.", + "`na_values_show` is FALSE: `na_values_icon_url` ignored.", fixed = TRUE )) suppressMessages(expect_message( map_dep(mica, feature = "n_obs", na_values_show = FALSE), - regexp = "`na_values_show` is FALSE: `na_values_icon_size` is ignored.", + "`na_values_show` is FALSE: `na_values_icon_size` is ignored.", fixed = TRUE )) @@ -142,20 +142,18 @@ test_that("map_dep() can calculate and get feature values", { ) suppressMessages(expect_message( map_dep(mica, feature = "rai", species = "krakeend"), - regexp = - glue::glue("There are 3 deployments without observations: {no_obs_deployments_str}"), + glue::glue("There are 3 deployments without observations: {no_obs_deployments_str}"), fixed = TRUE )) suppressMessages(expect_message( map_dep(mica, feature = "rai_individuals", species = "krakeend"), - regexp = - glue::glue("There are 3 deployments without observations: {no_obs_deployments_str}"), + glue::glue("There are 3 deployments without observations: {no_obs_deployments_str}"), fixed = TRUE )) expect_warning( map_dep(mica, feature = "n_species", species = "krakeend"), - regexp = "`species` ignored for `feature = n_species`", + "`species` ignored for `feature = n_species`", fixed = TRUE ) }) @@ -168,11 +166,11 @@ test_that("map_dep() allows for scale modifications", { relative_scale = FALSE )) expect_warning(map_dep(mica, feature = "effort", max_scale = 0), - regexp = "Relative scale used: max_scale value ignored.", + "Relative scale used: max_scale value ignored.", fixed = TRUE ) expect_error(map_dep(mica, feature = "effort", relative_scale = FALSE), - regexp = "If you use an absolute scale, `max_scale` must be a number, not `NULL`.", + "If you use an absolute scale, `max_scale` must be a number, not `NULL`.", fixed = TRUE ) }) @@ -205,17 +203,17 @@ test_that("map_dep() allows filtering by predicates", { expect_message( map_dep(mica, pred_gt("latitude", 51.18), feature = "n_species"), - regexp = "df %>% dplyr::filter((latitude > 51.18))", + "df %>% dplyr::filter((latitude > 51.18))", fixed = TRUE) suppressMessages(expect_message( map_dep(mica, pred_gt("latitude", 90), feature = "n_species"), - regexp = "No deployments left.", + "No deployments left.", fixed = TRUE)) suppressMessages(expect_message( map_dep(mica, pred_gt("latitude", 90), feature = "n_species"), - regexp = "df %>% dplyr::filter((latitude > 90))", + "df %>% dplyr::filter((latitude > 90))", fixed = TRUE)) }) @@ -232,7 +230,7 @@ test_that("Argument datapkg is deprecated: warning returned", { 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.", + "The `datapkg` argument of `map_dep()` is deprecated as of camtraptor 0.16.0.", fixed = TRUE ) }) diff --git a/tests/testthat/test-write_eml.R b/tests/testthat/test-write_eml.R index f68fbf8b..fcbd4d45 100644 --- a/tests/testthat/test-write_eml.R +++ b/tests/testthat/test-write_eml.R @@ -33,20 +33,24 @@ test_that("write_eml() can write an eml", { }) test_that("write_eml() checks for title", { - expect_error(write_eml(mica), - regexp = "The dataset must have a `title`.", - fixed = TRUE) + expect_error( + write_eml(mica), + "The dataset must have a `title`.", + fixed = TRUE + ) }) test_that("write_eml() checks for keywords", { - expect_error(write_eml(mica, title = "mica title", keywords = NULL), - regexp = "`keywords` should be a character (vector).", - fixed = TRUE) + expect_error( + write_eml(mica, title = "mica title", keywords = NULL), + "`keywords` should be a character (vector).", + fixed = TRUE + ) }) test_that("write_eml() notifies to check metadata", { suppressMessages(expect_message( write_eml(mica, title = "mica title", directory = NULL), - regexp = "Please review generated metadata carefully before publishing.", + "Please review generated metadata carefully before publishing.", fixed = TRUE)) }) From 46e40d7eda71d93d6743748528834dd69320ec8e Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Wed, 8 Nov 2023 12:14:47 +0100 Subject: [PATCH 36/39] Bump version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index bae56668..3afa368b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: camtraptor Title: Read, Explore and Visualize Camera Trap Data Packages -Version: 0.20.1 +Version: 0.20.2 Authors@R: c( person("Damiano", "Oldoni", email = "damiano.oldoni@inbo.be", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-3445-7562")), From 3472788846a2a523f86170804299aa72a766a6a0 Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Wed, 8 Nov 2023 12:16:11 +0100 Subject: [PATCH 37/39] Correct version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3afa368b..6e637177 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: camtraptor Title: Read, Explore and Visualize Camera Trap Data Packages -Version: 0.20.2 +Version: 0.21.0 Authors@R: c( person("Damiano", "Oldoni", email = "damiano.oldoni@inbo.be", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-3445-7562")), From 48f562632314f2ec42ece9e35713dcb7edce8302 Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Wed, 8 Nov 2023 13:04:52 +0100 Subject: [PATCH 38/39] Create NEWS.md --- NEWS.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 NEWS.md diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 00000000..8330eae0 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,8 @@ +# camtraptor 0.21.0 + +- `read_camtrap_dp()` supports Camtrap DP 1.0 (upcoming Agouti export format) + in favour of Camtrap DP 1.0-rc.1 (#284). + To avoid breaking changes to users, it will down-convert Camtrap DP 1.0 to + 0.1.6 which is currently used as internal data model for camtraptor. +- `get_custom_effort()` now calculates per calendar month/week (#219). +- `write_dwc()` has an updated mapping for dwc_audubon.csv (#274). From b6a0310911d9866681a8025db9b381b51ed7f8d9 Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Wed, 8 Nov 2023 15:30:09 +0100 Subject: [PATCH 39/39] Remove check on windows-latest + R 3.6.0 --- .github/workflows/R-CMD-check.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 38221a8e..ff1dc0c6 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -29,7 +29,6 @@ jobs: - {os: ubuntu-latest, r: 'release'} - {os: ubuntu-latest, r: 'oldrel-1'} - {os: ubuntu-latest, r: '3.6.3'} - - {os: windows-latest, r: '3.6.0'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}