From 778e4704fc99a5dcb8ec0acab19e5ca43b30f6ce Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:05:05 -0300 Subject: [PATCH 01/15] test n_min_length returns expected fusions --- tests/testthat/test-fusion-id.R | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/testthat/test-fusion-id.R b/tests/testthat/test-fusion-id.R index 3b4ca4d3..1baca391 100644 --- a/tests/testthat/test-fusion-id.R +++ b/tests/testthat/test-fusion-id.R @@ -121,3 +121,41 @@ test_that('larger n_min_length returns less unique fusionID', { fusion_id(edges, n_min_length = 0)[, uniqueN(fusionID)] ) }) + + +test_that('n_min_length returns expected number of unique fusionIDs', { + edges <- data.table( + dyadID = rep('A-B', 9), + timegroup = seq.int(10)[-5], + distance = c(1, 50, 1, 1, 1, 50, 1, 1, 50) + ) + threshold <- 25 + + expect_equal( + fusion_id( + edges, + threshold = threshold, + n_min_length = 0 + )[, uniqueN(fusionID, na.rm = TRUE)], + 4 + ) + + expect_equal( + fusion_id( + edges, + threshold = threshold, + n_min_length = 2 + )[, uniqueN(fusionID, na.rm = TRUE)], + 2 + ) + + expect_equal( + fusion_id( + edges, + threshold = threshold, + n_min_length = 3 + )[, uniqueN(fusionID, na.rm = TRUE)], + 0 + ) + +}) From a775f2f13965ccff34e8075fadb5b0e4da08553c Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:05:14 -0300 Subject: [PATCH 02/15] test allow_split returns expected --- tests/testthat/test-fusion-id.R | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/testthat/test-fusion-id.R b/tests/testthat/test-fusion-id.R index 1baca391..4d06ac5b 100644 --- a/tests/testthat/test-fusion-id.R +++ b/tests/testthat/test-fusion-id.R @@ -159,3 +159,46 @@ test_that('n_min_length returns expected number of unique fusionIDs', { ) }) + + +test_that('allow_split returns expected number of unique fusionIDs', { + expect_equal( + fusion_id( + edges, + threshold = threshold, + n_min_length = 2, + allow_split = FALSE + )[, uniqueN(fusionID, na.rm = TRUE)], + 2 + ) + + expect_equal( + fusion_id( + edges, + threshold = threshold, + n_min_length = 2, + allow_split = FALSE + )[!is.na(fusionID), .N, fusionID][, max(N)], + 2 + ) + + expect_equal( + fusion_id( + edges, + threshold = threshold, + n_min_length = 2, + allow_split = FALSE + )[, uniqueN(fusionID, na.rm = TRUE)], + 2 + ) + + expect_equal( + fusion_id( + edges, + threshold = threshold, + n_min_length = 2, + allow_split = TRUE + )[!is.na(fusionID), .N, fusionID][, max(N)], + 4 + ) +}) From 55b335a27f8ea8935d5a0728924f507e7eea79c7 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:05:25 -0300 Subject: [PATCH 03/15] test n_max_missing returns expected --- tests/testthat/test-fusion-id.R | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/testthat/test-fusion-id.R b/tests/testthat/test-fusion-id.R index 4d06ac5b..d56466e2 100644 --- a/tests/testthat/test-fusion-id.R +++ b/tests/testthat/test-fusion-id.R @@ -202,3 +202,29 @@ test_that('allow_split returns expected number of unique fusionIDs', { 4 ) }) + + +test_that('n_max_missing returns expected number of unique fusionIDs', { + expect_equal( + fusion_id( + edges, + threshold = threshold, + n_min_length = 2, + n_max_missing = 1, + allow_split = FALSE + )[, uniqueN(fusionID, na.rm = TRUE)], + 2 + ) + + expect_equal( + fusion_id( + edges, + threshold = threshold, + n_min_length = 2, + n_max_missing = 1, + allow_split = FALSE + )[!is.na(fusionID), .N, fusionID][, max(N)], + 3 + ) + +}) From b6a572dceea17770625c759c43e6c1ce3b0008f2 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:05:39 -0300 Subject: [PATCH 04/15] clarify dyad observation since edge input --- R/fusion_id.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/fusion_id.R b/R/fusion_id.R index 461a4cbd..b2b86d96 100644 --- a/R/fusion_id.R +++ b/R/fusion_id.R @@ -19,9 +19,9 @@ #' The \code{n_min_length} argument defines the minimum number of successive #' fixes that are required to establish a fusion event. The \code{n_max_missing} #' argument defines the the maximum number of allowable missing observations for -#' either individual in a dyad within a fusion event. The \code{allow_split} -#' argument defines if a single observation can be greater than the threshold -#' distance without initiating fission event. +#' the dyad within a fusion event. The \code{allow_split} argument defines if a +#' single observation can be greater than the threshold distance without +#' initiating fission event. #' #' @return \code{fusion_id} returns the input \code{edges} appended with a #' \code{fusionID} column. From 4717bc3ccba48dbe54072b0301ee7ae9b477baa5 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:06:22 -0300 Subject: [PATCH 05/15] fix missing test setup --- tests/testthat/test-fusion-id.R | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/testthat/test-fusion-id.R b/tests/testthat/test-fusion-id.R index d56466e2..a0ac4ce0 100644 --- a/tests/testthat/test-fusion-id.R +++ b/tests/testthat/test-fusion-id.R @@ -162,6 +162,13 @@ test_that('n_min_length returns expected number of unique fusionIDs', { test_that('allow_split returns expected number of unique fusionIDs', { + edges <- data.table( + dyadID = rep('A-B', 9), + timegroup = seq.int(10)[-5], + distance = c(1, 50, 1, 1, 1, 50, 1, 1, 50) + ) + threshold <- 25 + expect_equal( fusion_id( edges, @@ -205,6 +212,13 @@ test_that('allow_split returns expected number of unique fusionIDs', { test_that('n_max_missing returns expected number of unique fusionIDs', { + edges <- data.table( + dyadID = rep('A-B', 9), + timegroup = seq.int(10)[-5], + distance = c(1, 50, 1, 1, 1, 50, 1, 1, 50) + ) + threshold <- 25 + expect_equal( fusion_id( edges, From e152bdce1e4aa0c57c280db98f6771896e2385d0 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:24:26 -0300 Subject: [PATCH 06/15] mv edges out to use across all three sets of expectation tests --- tests/testthat/test-fusion-id.R | 45 ++++++++++++--------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/tests/testthat/test-fusion-id.R b/tests/testthat/test-fusion-id.R index a0ac4ce0..45f3ceb3 100644 --- a/tests/testthat/test-fusion-id.R +++ b/tests/testthat/test-fusion-id.R @@ -122,18 +122,17 @@ test_that('larger n_min_length returns less unique fusionID', { ) }) +edges_expected <- data.table( + dyadID = rep('A-B', 9), + timegroup = seq.int(10)[-5], + distance = c(1, 50, 1, 1, 1, 50, 1, 1, 50) +) +threshold <- 25 test_that('n_min_length returns expected number of unique fusionIDs', { - edges <- data.table( - dyadID = rep('A-B', 9), - timegroup = seq.int(10)[-5], - distance = c(1, 50, 1, 1, 1, 50, 1, 1, 50) - ) - threshold <- 25 - expect_equal( fusion_id( - edges, + edges_expected, threshold = threshold, n_min_length = 0 )[, uniqueN(fusionID, na.rm = TRUE)], @@ -142,7 +141,7 @@ test_that('n_min_length returns expected number of unique fusionIDs', { expect_equal( fusion_id( - edges, + edges_expected, threshold = threshold, n_min_length = 2 )[, uniqueN(fusionID, na.rm = TRUE)], @@ -151,7 +150,7 @@ test_that('n_min_length returns expected number of unique fusionIDs', { expect_equal( fusion_id( - edges, + edges_expected, threshold = threshold, n_min_length = 3 )[, uniqueN(fusionID, na.rm = TRUE)], @@ -162,16 +161,11 @@ test_that('n_min_length returns expected number of unique fusionIDs', { test_that('allow_split returns expected number of unique fusionIDs', { - edges <- data.table( - dyadID = rep('A-B', 9), - timegroup = seq.int(10)[-5], - distance = c(1, 50, 1, 1, 1, 50, 1, 1, 50) - ) - threshold <- 25 + expect_equal( fusion_id( - edges, + edges_expected, threshold = threshold, n_min_length = 2, allow_split = FALSE @@ -181,7 +175,7 @@ test_that('allow_split returns expected number of unique fusionIDs', { expect_equal( fusion_id( - edges, + edges_expected, threshold = threshold, n_min_length = 2, allow_split = FALSE @@ -191,7 +185,7 @@ test_that('allow_split returns expected number of unique fusionIDs', { expect_equal( fusion_id( - edges, + edges_expected, threshold = threshold, n_min_length = 2, allow_split = FALSE @@ -201,7 +195,7 @@ test_that('allow_split returns expected number of unique fusionIDs', { expect_equal( fusion_id( - edges, + edges_expected, threshold = threshold, n_min_length = 2, allow_split = TRUE @@ -212,16 +206,9 @@ test_that('allow_split returns expected number of unique fusionIDs', { test_that('n_max_missing returns expected number of unique fusionIDs', { - edges <- data.table( - dyadID = rep('A-B', 9), - timegroup = seq.int(10)[-5], - distance = c(1, 50, 1, 1, 1, 50, 1, 1, 50) - ) - threshold <- 25 - expect_equal( fusion_id( - edges, + edges_expected, threshold = threshold, n_min_length = 2, n_max_missing = 1, @@ -232,7 +219,7 @@ test_that('n_max_missing returns expected number of unique fusionIDs', { expect_equal( fusion_id( - edges, + edges_expected, threshold = threshold, n_min_length = 2, n_max_missing = 1, From 439f33e5f05d5628f07268c946eccb50d74c1b05 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:38:24 -0300 Subject: [PATCH 07/15] increase size of test edges --- tests/testthat/test-fusion-id.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-fusion-id.R b/tests/testthat/test-fusion-id.R index 45f3ceb3..871d499d 100644 --- a/tests/testthat/test-fusion-id.R +++ b/tests/testthat/test-fusion-id.R @@ -123,9 +123,9 @@ test_that('larger n_min_length returns less unique fusionID', { }) edges_expected <- data.table( - dyadID = rep('A-B', 9), - timegroup = seq.int(10)[-5], - distance = c(1, 50, 1, 1, 1, 50, 1, 1, 50) + dyadID = rep('A-B', 11), + timegroup = seq.int(12)[-5], + distance = c(1, 50, 1, 1, 1, 50, 50, 1, 1, 50, 1) ) threshold <- 25 @@ -136,7 +136,7 @@ test_that('n_min_length returns expected number of unique fusionIDs', { threshold = threshold, n_min_length = 0 )[, uniqueN(fusionID, na.rm = TRUE)], - 4 + 5 ) expect_equal( From 41512e4be20b02e8ff7dff397331053388b8c509 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:38:43 -0300 Subject: [PATCH 08/15] more allow split tests --- tests/testthat/test-fusion-id.R | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-fusion-id.R b/tests/testthat/test-fusion-id.R index 871d499d..5d2a0fc4 100644 --- a/tests/testthat/test-fusion-id.R +++ b/tests/testthat/test-fusion-id.R @@ -162,7 +162,6 @@ test_that('n_min_length returns expected number of unique fusionIDs', { test_that('allow_split returns expected number of unique fusionIDs', { - expect_equal( fusion_id( edges_expected, @@ -188,7 +187,7 @@ test_that('allow_split returns expected number of unique fusionIDs', { edges_expected, threshold = threshold, n_min_length = 2, - allow_split = FALSE + allow_split = TRUE )[, uniqueN(fusionID, na.rm = TRUE)], 2 ) @@ -206,6 +205,17 @@ test_that('allow_split returns expected number of unique fusionIDs', { test_that('n_max_missing returns expected number of unique fusionIDs', { + expect_equal( + fusion_id( + edges_expected, + threshold = threshold, + n_min_length = 0, + n_max_missing = 1, + allow_split = FALSE + )[, uniqueN(fusionID, na.rm = TRUE)], + 4 + ) + expect_equal( fusion_id( edges_expected, From 8a1b4545c30ff7b363f920f13142a343f46f05ee Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:39:00 -0300 Subject: [PATCH 09/15] more n max missing tests --- tests/testthat/test-fusion-id.R | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/testthat/test-fusion-id.R b/tests/testthat/test-fusion-id.R index 5d2a0fc4..44030259 100644 --- a/tests/testthat/test-fusion-id.R +++ b/tests/testthat/test-fusion-id.R @@ -238,4 +238,26 @@ test_that('n_max_missing returns expected number of unique fusionIDs', { 3 ) + expect_equal( + fusion_id( + edges_expected, + threshold = threshold, + n_min_length = 2, + n_max_missing = 1, + allow_split = TRUE + )[, uniqueN(fusionID, na.rm = TRUE)], + 2 + ) + + expect_equal( + fusion_id( + edges_expected, + threshold = threshold, + n_min_length = 2, + n_max_missing = 1, + allow_split = TRUE + )[!is.na(fusionID), .N, fusionID][, max(N)], + 5 + ) + }) From 6c790173dea69c9fbf29431bc009ec295b05542c Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:39:18 -0300 Subject: [PATCH 10/15] rm looking forward correct --- R/fusion_id.R | 8 -------- 1 file changed, 8 deletions(-) diff --git a/R/fusion_id.R b/R/fusion_id.R index b2b86d96..11151e02 100644 --- a/R/fusion_id.R +++ b/R/fusion_id.R @@ -160,14 +160,6 @@ fusion_id <- function(edges = NULL, both_rleid := (both_rleid + seq.int(.N)) * -1, by = dyadID] - # Correct if (looking forward) the loc is part of a new fusion run - unique_edges[, both_rleid := data.table::fifelse( - timegroup - data.table::shift(timegroup, -1) == -1 & - within & !(tg_diff), - data.table::shift(both_rleid, -1), - both_rleid - ), by = dyadID] - # If n minimum length > 0, check nrows and return NA if less than min if (n_min_length > 0) { unique_edges[!is.na(both_rleid), both_rleid := data.table::fifelse( From 0150d14cbe9414ef5967ca26dc1f87a0a2750fa1 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:39:26 -0300 Subject: [PATCH 11/15] man --- man/fusion_id.Rd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/man/fusion_id.Rd b/man/fusion_id.Rd index 27641225..2fc06ea6 100644 --- a/man/fusion_id.Rd +++ b/man/fusion_id.Rd @@ -60,9 +60,9 @@ indicate a 50 m distance threshold. The \code{n_min_length} argument defines the minimum number of successive fixes that are required to establish a fusion event. The \code{n_max_missing} argument defines the the maximum number of allowable missing observations for -either individual in a dyad within a fusion event. The \code{allow_split} -argument defines if a single observation can be greater than the threshold -distance without initiating fission event. +the dyad within a fusion event. The \code{allow_split} argument defines if a +single observation can be greater than the threshold distance without +initiating fission event. } \examples{ From 091066ca6228988ae2d29df164d994ad94d38a44 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:41:38 -0300 Subject: [PATCH 12/15] bump version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index fff9c703..a2416336 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: spatsoc Title: Group Animal Relocation Data by Spatial and Temporal Relationship -Version: 0.2.4.9000 +Version: 0.2.4.9001 Authors@R: c( person("Alec L.", "Robitaille", , "robit.alec@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-4706-1762")), From 810afc762fea957608d31afc43ae189823c59cfe Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:41:50 -0300 Subject: [PATCH 13/15] add tests for fusion id expected --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 7645d780..c66731ce 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# v 0.2.4.9001 + +* improve tests of `fusion_id` with tests for expected number of output fusionIDs [PR 83](https://github.com/ropensci/spatsoc/pull/83) + # v 0.2.4.9000 * (experimental) `fusion_id` function for flexibly identifying fission-fusion From e0f6ac0e9de6af58672367d75e802330933ed128 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:41:55 -0300 Subject: [PATCH 14/15] update codemeta --- codemeta.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codemeta.json b/codemeta.json index 7b61cb03..63c91ace 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci/spatsoc", "issueTracker": "https://github.com/ropensci/spatsoc/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.2.4.9000", + "version": "0.2.4.9001", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", @@ -190,7 +190,7 @@ }, "SystemRequirements": "GDAL (>= 2.0.1), GEOS (>= 3.4.0), PROJ (>= 4.8.0),\n sqlite3" }, - "fileSize": "1881.983KB", + "fileSize": "1884.503KB", "citation": [ { "@type": "ScholarlyArticle", From 0ff69cd5a718e6559560f1a8b1dff3552c9b1b5f Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Thu, 19 Sep 2024 16:41:57 -0300 Subject: [PATCH 15/15] update CITATION --- CITATION.cff | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CITATION.cff b/CITATION.cff index 3f20f0ff..09c31426 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -8,7 +8,7 @@ message: 'To cite package "spatsoc" in publications use:' type: software license: GPL-3.0-only title: 'spatsoc: Group Animal Relocation Data by Spatial and Temporal Relationship' -version: 0.2.4.9000 +version: 0.2.4.9001 identifiers: - type: doi value: 10.32614/CRAN.package.spatsoc