From 483b59e80fe5fd9b3d4f3fcb74014ce9dc691b60 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Fri, 19 Jul 2024 12:03:12 -0300 Subject: [PATCH 01/42] fst edge delay --- R/edge_delay.R | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 R/edge_delay.R diff --git a/R/edge_delay.R b/R/edge_delay.R new file mode 100644 index 00000000..da9654c2 --- /dev/null +++ b/R/edge_delay.R @@ -0,0 +1,58 @@ +#' Directional correlation delay edge lists +#' +#' Temporal delay in absolute bearing between individuals +#' +#' @param DT relocation data +#' @param edges edges generated with edges_dist +#' @param window integer window in timegroups generated with group_times +edge_delay <- function(DT, id = NULL, edges, window = NULL) { + stopifnot(!is.null(id)) + stopifnot(!is.null(window)) + + stopifnot(id %in% colnames(DT)) + + setnames(DT, id, 'id') + + stopifnot('dyadID' %in% colnames(edges)) + stopifnot('timegroup' %in% colnames(edges)) + stopifnot('fusionID' %in% colnames(edges)) + stopifnot('dyadID' %in% colnames(edges)) + + stopifnot('bearing' %in% colnames(DT)) + stopifnot('timegroup' %in% colnames(DT)) + + # TODO: check window isnt in colnames + + setorder(DT, timegroup) + + id_tg <- edges[!is.na(fusionID), .( + tg = unique(timegroup), + dyadID = unique(dyadID), + ID1 = first(ID1), + ID2 = first(ID2) + ), by = fusionID] + id_tg[, min_tg := data.table::fifelse(tg - window < min(tg), min(tg), tg - window), + by = fusionID] + id_tg[, max_tg := data.table::fifelse(tg + window < min(tg), min(tg), tg + window), + by = fusionID] + + id_tg[, delay_tg := { + focal_bearing <- DT[timegroup == .BY$tg & id == ID1, bearing] + DT[between(timegroup, min_tg, max_tg) & id == ID2, + timegroup[which.min(delta_rad(focal_bearing, bearing))]] + }, by = .(tg, dyadID)] + + id_tg[, dir_corr_delay := tg - delay_tg] + + data.table::setnames(id_tg, c('tg'), c('timegroup')) + data.table::set(id_tg, j = c('min_tg', 'max_tg','delay_tg'), value = NULL) + data.table::setorder(id_tg, timegroup, ID1, ID2, dir_corr_delay) + + out <- data.table::rbindlist(list( + id_tg, + id_tg[, .(timegroup, dyadID, fusionID, + ID1 = ID2, ID2 = ID1, dir_corr_delay = - dir_corr_delay)] + ), use.names = TRUE) + + return(out) +} From 0b89f6d0b286d68c3928852d2583cb67c3ca334f Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Fri, 1 Nov 2024 16:25:21 -0300 Subject: [PATCH 02/42] internal delta_rad function --- R/internal.R | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 R/internal.R diff --git a/R/internal.R b/R/internal.R new file mode 100644 index 00000000..2811ff04 --- /dev/null +++ b/R/internal.R @@ -0,0 +1,29 @@ +#' Difference of two angles measured in radians +#' +#' Internal function +#' +#' @param target angle in radians +#' @param source angle in radians +#' @param signed boolean if signed difference should be returned, default FALSE +#' +#' @return +#' @references adapted from https://stackoverflow.com/a/7869457 +#' +#' @examples +delta_rad <- function(target, source, signed = FALSE) { + if (!inherits(target, 'units') || units(target$numerator != 'rad')) { + stop('units(targets) is not radians') + } + if (!inherits(source, 'units') || units(target$numerator != 'rad')) { + stop('units(source) is not radians') + } + + d <- source - target + d <- (d + pi) %% (2 * pi) - pi + + if (signed) { + return(d) + } else { + return(abs(d)) + } +} From 455568e29e72798de2d783eb815725575f2a91d7 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 16:44:32 -0400 Subject: [PATCH 03/42] title --- R/edge_delay.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index da9654c2..65ba66c8 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -1,4 +1,4 @@ -#' Directional correlation delay edge lists +#' Directional correlation delay based edge lists #' #' Temporal delay in absolute bearing between individuals #' From a458550ac578104a1dd1c1176424048ab13a7d93 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 16:44:38 -0400 Subject: [PATCH 04/42] description --- R/edge_delay.R | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index 65ba66c8..cdcd6317 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -1,11 +1,26 @@ #' Directional correlation delay based edge lists #' -#' Temporal delay in absolute bearing between individuals +#' \code{edge_delay} returns edge lists defined by the directional correlation +#' delay between individuals. The function expects a \code{data.table} with +#' relocation data, distance based edge lists, individual identifiers and a window argument. The +#' window argument is used to specify the temporal window within which to consider +#' the directional correlation delay. Relocation data should be in two columns +#' representing the X and Y coordinates. +#' +#' The \code{DT} and \code{edges} must be \code{data.table}s. If your data is a +#' \code{data.frame}, you can convert it by reference using +#' \code{\link[data.table:setDT]{data.table::setDT}}. +#' +#' The \code{DT} and \code{edges} are internally matched in this function using +#' the columns \code{timegroup} (from \code{group_times}) and \code{ID1} and +#' \code{ID2} (in \code{edges}, from \code{dyad_id}) with \code{id} (in +#' \code{DT}). This function expects a \code{fusionID} present, generated with +#' the \code{fusion_id} function. The \code{timegroup} argument expects the +#' names of a column in \code{edges} which correspond to the timegroup column. +#' The \code{id}, \code{direction} and \code{timegroup} arguments expect the names +#' of a column in \code{DT} which correspond to the id, direction and +#' timegroup columns. #' -#' @param DT relocation data -#' @param edges edges generated with edges_dist -#' @param window integer window in timegroups generated with group_times -edge_delay <- function(DT, id = NULL, edges, window = NULL) { stopifnot(!is.null(id)) stopifnot(!is.null(window)) From 79d67929f295bc6ab83d1c8eb8ef1279f23f2a89 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 16:44:41 -0400 Subject: [PATCH 05/42] params --- R/edge_delay.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/edge_delay.R b/R/edge_delay.R index cdcd6317..b091061d 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -21,6 +21,11 @@ #' of a column in \code{DT} which correspond to the id, direction and #' timegroup columns. #' +#' @inheritParams centroid_fusion +#' @inheritParams direction_group +#' @param window temporal window in unit of timegroup column generated with +#' \code{group_times}, eg. \code{window = 4} corresponds to the 4 timegroups +#' before and after the focal observation stopifnot(!is.null(id)) stopifnot(!is.null(window)) From 6f864c60f0fd193f48f601139a6f8f952c3e5a8a Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 16:44:43 -0400 Subject: [PATCH 06/42] return --- R/edge_delay.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/edge_delay.R b/R/edge_delay.R index b091061d..17795a36 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -26,6 +26,11 @@ #' @param window temporal window in unit of timegroup column generated with #' \code{group_times}, eg. \code{window = 4} corresponds to the 4 timegroups #' before and after the focal observation +#' +#' @return \code{edge_delay} returns the input \code{edges} appended with +#' a 'dir_corr_delay' column indicating the temporal delay (in units of +#' timegroups) at which ID1's direction of movement is most similar to +#' ID2's direction of movement, within the temporal window defined. stopifnot(!is.null(id)) stopifnot(!is.null(window)) From 7dfb16a2de1562d7e59eeef80186e21fc291647b Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 16:46:22 -0400 Subject: [PATCH 07/42] example --- R/edge_delay.R | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/R/edge_delay.R b/R/edge_delay.R index 17795a36..43d666bf 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -31,6 +31,62 @@ #' a 'dir_corr_delay' column indicating the temporal delay (in units of #' timegroups) at which ID1's direction of movement is most similar to #' ID2's direction of movement, within the temporal window defined. +#' +#' @export +#' +#' @family Edge-list generation +#' +#' @examples +#' # Load data.table +#' library(data.table) +#' \dontshow{data.table::setDTthreads(1)} +#' +#' # Read example data +#' DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc")) +#' +#' # Select only individuals A, B, C for this example +#' DT <- DT[ID %in% c('A', 'B', 'C')] +#' +#' # Cast the character column to POSIXct +#' DT[, datetime := as.POSIXct(datetime, tz = 'UTC')] +#' +#' # Temporal grouping +#' group_times(DT, datetime = 'datetime', threshold = '20 minutes') +#' +#' # Calculate direction +#' direction_step( +#' DT = DT, +#' id = 'ID', +#' coords = c('X', 'Y'), +#' projection = 32736 +#' ) +#' +#' # Distance based edge list generation +#' edges <- edge_dist( +#' DT, +#' threshold = 100, +#' id = 'ID', +#' coords = c('X', 'Y'), +#' timegroup = 'timegroup', +#' returnDist = TRUE, +#' fillNA = FALSE +#' ) +#' +#' # Generate dyad id +#' dyad_id(edges, id1 = 'ID1', id2 = 'ID2') +#' +#' # Generate fusion id +#' fusion_id(edges, threshold = 100) +#' +#' # Directional correlation delay +#' delay <- edge_delay( +#' DT, +#' edges, +#' window = 3, +#' id = 'id' +#' ) +#' +#' print(delay) stopifnot(!is.null(id)) stopifnot(!is.null(window)) From 331960db91b4a0b8c41f04c31da2e7ec9bb320b3 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 16:46:25 -0400 Subject: [PATCH 08/42] args --- R/edge_delay.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/R/edge_delay.R b/R/edge_delay.R index 43d666bf..650b6da4 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -87,6 +87,14 @@ #' ) #' #' print(delay) +edge_delay <- function( + DT, + edges, + window, + id = NULL, + direction = 'direction', + timegroup = 'timegroup') { + stopifnot(!is.null(id)) stopifnot(!is.null(window)) From 02886352d99808dc8243a8e7e885db38f33af6e4 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:12:48 -0400 Subject: [PATCH 09/42] rm timegroup arg --- R/edge_delay.R | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index 650b6da4..36ecf59d 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -15,11 +15,9 @@ #' the columns \code{timegroup} (from \code{group_times}) and \code{ID1} and #' \code{ID2} (in \code{edges}, from \code{dyad_id}) with \code{id} (in #' \code{DT}). This function expects a \code{fusionID} present, generated with -#' the \code{fusion_id} function. The \code{timegroup} argument expects the -#' names of a column in \code{edges} which correspond to the timegroup column. -#' The \code{id}, \code{direction} and \code{timegroup} arguments expect the names -#' of a column in \code{DT} which correspond to the id, direction and -#' timegroup columns. +#' the \code{fusion_id} function. +#' The \code{id}, and \code{direction} arguments expect the names +#' of a column in \code{DT} which correspond to the id, and direction columns. #' #' @inheritParams centroid_fusion #' @inheritParams direction_group @@ -92,8 +90,7 @@ edge_delay <- function( edges, window, id = NULL, - direction = 'direction', - timegroup = 'timegroup') { + direction = 'direction') { stopifnot(!is.null(id)) stopifnot(!is.null(window)) From 1e431c4aaaaff2f369deb913f63cc279db0e8b8e Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:12:55 -0400 Subject: [PATCH 10/42] fix id colname --- R/edge_delay.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index 36ecf59d..0535b4a8 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -81,7 +81,7 @@ #' DT, #' edges, #' window = 3, -#' id = 'id' +#' id = 'ID' #' ) #' #' print(delay) From 567aba6cbec32ab64e99a373197f86135f12445c Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:13:00 -0400 Subject: [PATCH 11/42] set window default null --- R/edge_delay.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index 0535b4a8..1af36441 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -88,7 +88,7 @@ edge_delay <- function( DT, edges, - window, + window = NULL, id = NULL, direction = 'direction') { From 1b25f48911ceda89a2b8ba533fb7ca393794977e Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:13:06 -0400 Subject: [PATCH 12/42] check dt --- R/edge_delay.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index 1af36441..d226c9de 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -92,8 +92,9 @@ edge_delay <- function( id = NULL, direction = 'direction') { - stopifnot(!is.null(id)) - stopifnot(!is.null(window)) + if (is.null(DT)) { + stop('input DT required') + } stopifnot(id %in% colnames(DT)) From 2918e1c05f1f2564eb80601dd1faf1ce441c836e Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:13:08 -0400 Subject: [PATCH 13/42] check edges --- R/edge_delay.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index d226c9de..269ac2d6 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -96,7 +96,9 @@ edge_delay <- function( stop('input DT required') } - stopifnot(id %in% colnames(DT)) + if (is.null(edges)) { + stop('input edges required') + } setnames(DT, id, 'id') From 891b1c070de2302b8d298b79ceb7f6b6f0290680 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:13:15 -0400 Subject: [PATCH 14/42] check id colname --- R/edge_delay.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index 269ac2d6..7ccf91c8 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -100,7 +100,9 @@ edge_delay <- function( stop('input edges required') } - setnames(DT, id, 'id') + if (is.null(id)) { + stop('id column name required') + } stopifnot('dyadID' %in% colnames(edges)) stopifnot('timegroup' %in% colnames(edges)) From 03908e305d0454cf540472b53e55b891fc1eb8b6 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:13:28 -0400 Subject: [PATCH 15/42] check cols --- R/edge_delay.R | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index 7ccf91c8..9bf6cd98 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -104,13 +104,28 @@ edge_delay <- function( stop('id column name required') } - stopifnot('dyadID' %in% colnames(edges)) - stopifnot('timegroup' %in% colnames(edges)) - stopifnot('fusionID' %in% colnames(edges)) - stopifnot('dyadID' %in% colnames(edges)) + check_cols_edges <- c('ID1', 'ID2', timegroup) + if (any(!(check_cols_edges %in% colnames(edges)))) { + stop(paste0( + as.character(paste(setdiff( + check_cols_edges, + colnames(edges) + ), collapse = ', ')), + ' field(s) provided are not present in input DT' + )) + } - stopifnot('bearing' %in% colnames(DT)) - stopifnot('timegroup' %in% colnames(DT)) + check_cols_DT <- c(id, timegroup, direction) + if (any(!(check_cols_DT %in% colnames(DT) + ))) { + stop(paste0( + as.character(paste(setdiff( + check_cols_DT, + colnames(DT) + ), collapse = ', ')), + ' field(s) provided are not present in input DT' + )) + } # TODO: check window isnt in colnames From a72103992b497cbc4f2a6e2dee9d60c72d84169c Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:13:31 -0400 Subject: [PATCH 16/42] check window --- R/edge_delay.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/R/edge_delay.R b/R/edge_delay.R index 9bf6cd98..0eac74cf 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -127,6 +127,13 @@ edge_delay <- function( )) } + if (is.null(window)) { + stop('window is required') + } + + if (!is.numeric(window)) { + stop('window should be a numeric, in the units of timegroup') + } # TODO: check window isnt in colnames setorder(DT, timegroup) From b74e4b8f1f99f246e4b5a96e7364241c094d418d Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:13:35 -0400 Subject: [PATCH 17/42] check dyad, fusion ids --- R/edge_delay.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/R/edge_delay.R b/R/edge_delay.R index 0eac74cf..a5afc5d9 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -134,6 +134,14 @@ edge_delay <- function( if (!is.numeric(window)) { stop('window should be a numeric, in the units of timegroup') } + + if (!'fusionID' %in% colnames(edges)) { + stop('fusionID not present in edges, did you run fusion_id?') + } + + if (!'dyadID' %in% colnames(edges)) { + stop('dyadID not present in edges, did you run dyad_id?') + } # TODO: check window isnt in colnames setorder(DT, timegroup) From a94bada135fdf5992fa4092143e30ec50c2f1f68 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:32:22 -0400 Subject: [PATCH 18/42] fix check numerator brackets --- R/internal.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/internal.R b/R/internal.R index 2811ff04..3f23d7c0 100644 --- a/R/internal.R +++ b/R/internal.R @@ -11,10 +11,10 @@ #' #' @examples delta_rad <- function(target, source, signed = FALSE) { - if (!inherits(target, 'units') || units(target$numerator != 'rad')) { + if (!inherits(target, 'units') || units(target)$numerator != 'rad') { stop('units(targets) is not radians') } - if (!inherits(source, 'units') || units(target$numerator != 'rad')) { + if (!inherits(source, 'units') || units(source)$numerator != 'rad') { stop('units(source) is not radians') } From 294d5ce7158fdf4d91ce429f849af51612acf2cc Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:32:29 -0400 Subject: [PATCH 19/42] fix units --- R/internal.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/internal.R b/R/internal.R index 3f23d7c0..6811a400 100644 --- a/R/internal.R +++ b/R/internal.R @@ -19,7 +19,8 @@ delta_rad <- function(target, source, signed = FALSE) { } d <- source - target - d <- (d + pi) %% (2 * pi) - pi + pi_rad <- units::as_units(pi, 'rad') + d <- (d + pi_rad) %% (2 * pi_rad) - pi_rad if (signed) { return(d) From 595ce9da6a3c21c3f87b9e8e3e91b314d32fc21f Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:36:09 -0400 Subject: [PATCH 20/42] check if window in colnames, zz temporarily if so --- R/edge_delay.R | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index a5afc5d9..ce6b3d7a 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -142,7 +142,13 @@ edge_delay <- function( if (!'dyadID' %in% colnames(edges)) { stop('dyadID not present in edges, did you run dyad_id?') } - # TODO: check window isnt in colnames + if ('window' %in% colnames(DT)) { + setnames(DT, 'window', 'zz_window') + } + + if ('window' %in% colnames(edges)) { + setnames(edges, 'window', 'zz_window') + } setorder(DT, timegroup) @@ -175,5 +181,13 @@ edge_delay <- function( ID1 = ID2, ID2 = ID1, dir_corr_delay = - dir_corr_delay)] ), use.names = TRUE) + if ('zz_window' %in% colnames(DT)) { + setnames(DT, 'zz_window', 'window') + } + + if ('zz_window' %in% colnames(edges)) { + setnames(edges, 'zz_window', 'window') + } + return(out) } From f85b1e894123009ae7ad5e09f805417f9dbfe74f Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:40:41 -0400 Subject: [PATCH 21/42] use three zees --- R/edge_delay.R | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index ce6b3d7a..6a82e3b2 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -143,13 +143,14 @@ edge_delay <- function( stop('dyadID not present in edges, did you run dyad_id?') } if ('window' %in% colnames(DT)) { - setnames(DT, 'window', 'zz_window') + setnames(DT, 'window', 'zzz_window') } if ('window' %in% colnames(edges)) { - setnames(edges, 'window', 'zz_window') + setnames(edges, 'window', 'zzz_window') } + setnames(DT, id, 'zzz_id') setorder(DT, timegroup) id_tg <- edges[!is.na(fusionID), .( @@ -165,9 +166,9 @@ edge_delay <- function( id_tg[, delay_tg := { focal_bearing <- DT[timegroup == .BY$tg & id == ID1, bearing] - DT[between(timegroup, min_tg, max_tg) & id == ID2, - timegroup[which.min(delta_rad(focal_bearing, bearing))]] - }, by = .(tg, dyadID)] + DT[between(timegroup, min_tg, max_tg) & zzz_id == ID2, + timegroup[which.min(delta_rad(focal_direction, direction))]] + by = c('tg', 'dyadID')] id_tg[, dir_corr_delay := tg - delay_tg] @@ -181,12 +182,12 @@ edge_delay <- function( ID1 = ID2, ID2 = ID1, dir_corr_delay = - dir_corr_delay)] ), use.names = TRUE) - if ('zz_window' %in% colnames(DT)) { - setnames(DT, 'zz_window', 'window') + if ('zzz_window' %in% colnames(DT)) { + setnames(DT, 'zzz_window', 'window') } - if ('zz_window' %in% colnames(edges)) { - setnames(edges, 'zz_window', 'window') + if ('zzz_window' %in% colnames(edges)) { + setnames(edges, 'zzz_window', 'window') } return(out) From 2f434ca734a6424410ac1908dd5bd226c110ae61 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:40:59 -0400 Subject: [PATCH 22/42] tidy --- R/edge_delay.R | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index 6a82e3b2..cc9233a1 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -142,6 +142,8 @@ edge_delay <- function( if (!'dyadID' %in% colnames(edges)) { stop('dyadID not present in edges, did you run dyad_id?') } + + if ('window' %in% colnames(DT)) { setnames(DT, 'window', 'zzz_window') } @@ -158,11 +160,15 @@ edge_delay <- function( dyadID = unique(dyadID), ID1 = first(ID1), ID2 = first(ID2) - ), by = fusionID] - id_tg[, min_tg := data.table::fifelse(tg - window < min(tg), min(tg), tg - window), - by = fusionID] - id_tg[, max_tg := data.table::fifelse(tg + window < min(tg), min(tg), tg + window), - by = fusionID] + ), by = c('fusionID')] + + id_tg[, min_tg := + data.table::fifelse(tg - window < min(tg), min(tg), tg - window), + by = c('fusionID')] + + id_tg[, max_tg := + data.table::fifelse(tg + window < min(tg), min(tg), tg + window), + by = c('fusionID')] id_tg[, delay_tg := { focal_bearing <- DT[timegroup == .BY$tg & id == ID1, bearing] From f55753cc065eed684180107875693fae9527175b Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:41:05 -0400 Subject: [PATCH 23/42] fix direction not bearing --- R/edge_delay.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index cc9233a1..517f094b 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -171,9 +171,10 @@ edge_delay <- function( by = c('fusionID')] id_tg[, delay_tg := { - focal_bearing <- DT[timegroup == .BY$tg & id == ID1, bearing] + focal_direction <- DT[timegroup == .BY$tg & zzz_id == ID1, direction] DT[between(timegroup, min_tg, max_tg) & zzz_id == ID2, timegroup[which.min(delta_rad(focal_direction, direction))]] + }, by = c('tg', 'dyadID')] id_tg[, dir_corr_delay := tg - delay_tg] From 42fbf67fa20dd553ce491fadd5a3bb6f18d99af2 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 17:41:11 -0400 Subject: [PATCH 24/42] tidy --- R/edge_delay.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index 517f094b..fb47f7d7 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -179,8 +179,9 @@ edge_delay <- function( id_tg[, dir_corr_delay := tg - delay_tg] - data.table::setnames(id_tg, c('tg'), c('timegroup')) + data.table::setnames(id_tg, 'tg', 'timegroup') data.table::set(id_tg, j = c('min_tg', 'max_tg','delay_tg'), value = NULL) + data.table::setorder(id_tg, timegroup, ID1, ID2, dir_corr_delay) out <- data.table::rbindlist(list( From 444652704b0c76db5ec26d678f6383409788bce3 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 18:42:52 -0400 Subject: [PATCH 25/42] fix reset zzz id --- R/edge_delay.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/edge_delay.R b/R/edge_delay.R index fb47f7d7..6f76c16e 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -190,6 +190,9 @@ edge_delay <- function( ID1 = ID2, ID2 = ID1, dir_corr_delay = - dir_corr_delay)] ), use.names = TRUE) + + setnames(DT, 'zzz_id', id) + if ('zzz_window' %in% colnames(DT)) { setnames(DT, 'zzz_window', 'window') } From 981c2acaeb486e8e787d6dbb2924c3fcf4fdfb54 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 18:43:29 -0400 Subject: [PATCH 26/42] todo check max tg --- R/edge_delay.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/edge_delay.R b/R/edge_delay.R index 6f76c16e..cd60e43b 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -168,6 +168,8 @@ edge_delay <- function( id_tg[, max_tg := data.table::fifelse(tg + window < min(tg), min(tg), tg + window), + # TODO: check max_tg + # data.table::fifelse(tg + window > max(tg), max(tg), tg + window), by = c('fusionID')] id_tg[, delay_tg := { From d3b1cbb67413fb91c8ec253f9884ae74b350ebc7 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 19:07:04 -0400 Subject: [PATCH 27/42] fix timegroup char since not arg --- R/edge_delay.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index cd60e43b..4e3a7714 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -104,7 +104,7 @@ edge_delay <- function( stop('id column name required') } - check_cols_edges <- c('ID1', 'ID2', timegroup) + check_cols_edges <- c('ID1', 'ID2', 'timegroup') if (any(!(check_cols_edges %in% colnames(edges)))) { stop(paste0( as.character(paste(setdiff( @@ -115,7 +115,7 @@ edge_delay <- function( )) } - check_cols_DT <- c(id, timegroup, direction) + check_cols_DT <- c(id, 'timegroup', direction) if (any(!(check_cols_DT %in% colnames(DT) ))) { stop(paste0( @@ -153,7 +153,7 @@ edge_delay <- function( } setnames(DT, id, 'zzz_id') - setorder(DT, timegroup) + data.table::setorderv(DT, 'timegroup') id_tg <- edges[!is.na(fusionID), .( tg = unique(timegroup), From d54bf05eae7481438ed5bde152db69f7caa8e76b Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 19:36:23 -0400 Subject: [PATCH 28/42] rm setnames, use env --- R/edge_delay.R | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index 4e3a7714..6f6cba9f 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -152,7 +152,6 @@ edge_delay <- function( setnames(edges, 'window', 'zzz_window') } - setnames(DT, id, 'zzz_id') data.table::setorderv(DT, 'timegroup') id_tg <- edges[!is.na(fusionID), .( @@ -173,9 +172,11 @@ edge_delay <- function( by = c('fusionID')] id_tg[, delay_tg := { - focal_direction <- DT[timegroup == .BY$tg & zzz_id == ID1, direction] - DT[between(timegroup, min_tg, max_tg) & zzz_id == ID2, - timegroup[which.min(delta_rad(focal_direction, direction))]] + focal_direction <- DT[timegroup == .BY$tg & + id == ID1, direction] + DT[between(timegroup, min_tg, max_tg) & id == ID2, + timegroup[which.min(delta_rad(focal_direction, direction))], + env = list(id = 'id')] }, by = c('tg', 'dyadID')] @@ -192,9 +193,6 @@ edge_delay <- function( ID1 = ID2, ID2 = ID1, dir_corr_delay = - dir_corr_delay)] ), use.names = TRUE) - - setnames(DT, 'zzz_id', id) - if ('zzz_window' %in% colnames(DT)) { setnames(DT, 'zzz_window', 'window') } @@ -205,3 +203,4 @@ edge_delay <- function( return(out) } + From ada1d55cf4ad1539da90a745bf203df792f9936c Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 19:39:26 -0400 Subject: [PATCH 29/42] fst test edge_delay --- tests/testthat/test-edge-delay.R | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/testthat/test-edge-delay.R diff --git a/tests/testthat/test-edge-delay.R b/tests/testthat/test-edge-delay.R new file mode 100644 index 00000000..8a98ed50 --- /dev/null +++ b/tests/testthat/test-edge-delay.R @@ -0,0 +1,2 @@ +# Test edge_delay +context('test edge_delay') From 5538f3080f816467c815fbafc2462c91efdb3a3f Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 19:39:51 -0400 Subject: [PATCH 30/42] test setup --- tests/testthat/test-edge-delay.R | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/testthat/test-edge-delay.R b/tests/testthat/test-edge-delay.R index 8a98ed50..5f89f8f8 100644 --- a/tests/testthat/test-edge-delay.R +++ b/tests/testthat/test-edge-delay.R @@ -1,2 +1,29 @@ # Test edge_delay context('test edge_delay') + +library(spatsoc) + +DT <- fread('../testdata/DT.csv') +id <- 'ID' +datetime <- 'datetime' +timethreshold <- '20 minutes' +threshold <- 50 +coords <- c('X', 'Y') +timegroup <- 'timegroup' +group <- 'group' +projection <- 32736 +window <- 3 + + +DT[, datetime := as.POSIXct(datetime, tz = 'UTC')] +group_times(DT, datetime = datetime, threshold = timethreshold) +direction_step(DT, id, coords, projection) +edges <- edge_dist(DT, threshold = threshold, id = id, + timegroup = timegroup, returnDist = TRUE, fillNA = FALSE) +dyad_id(edges, id1 = 'ID1', id2 = 'ID2') +fusion_id(edges, threshold = threshold) + +clean_DT <- copy(DT) +clean_edges <- copy(edges) + +# edge_delay(DT = DT, edges = edges, id = id, window = window) From ac2091a5ae0e3594bac11402903fa23604ba6e0a Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 19:41:48 -0400 Subject: [PATCH 31/42] reorg args --- R/edge_delay.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index 6f6cba9f..bb05a702 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -7,11 +7,11 @@ #' the directional correlation delay. Relocation data should be in two columns #' representing the X and Y coordinates. #' -#' The \code{DT} and \code{edges} must be \code{data.table}s. If your data is a +#' The \code{edges} and \code{DT} must be \code{data.table}s. If your data is a #' \code{data.frame}, you can convert it by reference using #' \code{\link[data.table:setDT]{data.table::setDT}}. #' -#' The \code{DT} and \code{edges} are internally matched in this function using +#' The \code{edges} and \code{DT} are internally matched in this function using #' the columns \code{timegroup} (from \code{group_times}) and \code{ID1} and #' \code{ID2} (in \code{edges}, from \code{dyad_id}) with \code{id} (in #' \code{DT}). This function expects a \code{fusionID} present, generated with @@ -78,16 +78,16 @@ #' #' # Directional correlation delay #' delay <- edge_delay( -#' DT, -#' edges, +#' edges = edges, +#' DT = DT, #' window = 3, #' id = 'ID' #' ) #' #' print(delay) edge_delay <- function( - DT, edges, + DT, window = NULL, id = NULL, direction = 'direction') { From 21808d2ac4a44e10df361afeeff2ee2cf92baf0c Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 19:46:47 -0400 Subject: [PATCH 32/42] test required arg --- tests/testthat/test-edge-delay.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/testthat/test-edge-delay.R b/tests/testthat/test-edge-delay.R index 5f89f8f8..b2136760 100644 --- a/tests/testthat/test-edge-delay.R +++ b/tests/testthat/test-edge-delay.R @@ -27,3 +27,16 @@ clean_DT <- copy(DT) clean_edges <- copy(edges) # edge_delay(DT = DT, edges = edges, id = id, window = window) + +test_that('edges, DT are required', { + expect_error(edge_delay(edges, DT = NULL)) + expect_error(edge_delay(edges = NULL, DT)) +}) + +test_that('arguments required, otherwise error detected', { + expect_error(edge_delay(edges, DT, id = NULL), + 'id column name required') + expect_error(edge_delay(edges, DT, id = id, window = NULL), + 'window is required') +}) + From 6a12bb57ec687d5b7df84cdd67e85911054c9f97 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 19:46:52 -0400 Subject: [PATCH 33/42] test window numeric --- tests/testthat/test-edge-delay.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/testthat/test-edge-delay.R b/tests/testthat/test-edge-delay.R index b2136760..459644d9 100644 --- a/tests/testthat/test-edge-delay.R +++ b/tests/testthat/test-edge-delay.R @@ -40,3 +40,8 @@ test_that('arguments required, otherwise error detected', { 'window is required') }) +test_that('window is numeric', { + expect_error(edge_delay(edges, DT, id = id, window = 'potato'), + 'numeric') +}) + From 8ad56a552faa4a3d1f201dee17ebe708546ab8a1 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 19:47:02 -0400 Subject: [PATCH 34/42] test colnames exist --- tests/testthat/test-edge-delay.R | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/testthat/test-edge-delay.R b/tests/testthat/test-edge-delay.R index 459644d9..49c501ac 100644 --- a/tests/testthat/test-edge-delay.R +++ b/tests/testthat/test-edge-delay.R @@ -45,3 +45,31 @@ test_that('window is numeric', { 'numeric') }) +test_that('column names must exist in DT', { + expect_error(edge_delay(edges, DT, id = 'potato'), + 'potato field') + + copy_edges <- copy(clean_edges) + copy_edges[, timegroup := NULL] + expect_error(edge_delay(edges, DT, id = id), + 'timegroup field') + + copy_edges <- copy(clean_edges) + copy_edges[, fusionID := NULL] + expect_error(edge_delay(edges, DT, id = id), + 'fusionID field') + + copy_edges <- copy(clean_edges) + copy_edges[, dyadID := NULL] + expect_error(edge_delay(edges, DT, id = id), + 'dyadID field') + + expect_error(edge_delay(edges, DT, id = id, direction = 'potato'), + 'direction field') + + copy_DT <- copy(clean_DT) + copy_DT[, timegroup := NULL] + expect_error(edge_delay(edges, DT, id = id), + 'timegroup field') +}) + From ccadff47ec5dafdbba9285111b8eca0f2b62fdf1 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 19:47:11 -0400 Subject: [PATCH 35/42] test returned object --- tests/testthat/test-edge-delay.R | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/testthat/test-edge-delay.R b/tests/testthat/test-edge-delay.R index 49c501ac..003ce81f 100644 --- a/tests/testthat/test-edge-delay.R +++ b/tests/testthat/test-edge-delay.R @@ -73,3 +73,23 @@ test_that('column names must exist in DT', { 'timegroup field') }) +test_that('no rows are added to the result edges', { + expect_equal(nrow(edges), + nrow(edge_delay(edges, DT, id = id, window = window))) +}) + +test_that('two columns added to the result DT', { + copyEdges <- copy(edges) + + expect_equal(ncol(copyEdges) + 1, + ncol(edge_delay(edges, DT, id = id, window = window))) +}) + +test_that('column added to the result DT is double', { + expect_type(edge_delay(edges, DT, id = id, window = window)$dir_corr_delay, 'double') +}) + +test_that('returns a data.table', { + expect_s3_class(edge_delay(edges, DT, id = id, window = window), 'data.table') +}) + From 7752d041174c6929f36a103e394f7dcdd5351087 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 19:52:05 -0400 Subject: [PATCH 36/42] fix missing coords arg --- tests/testthat/test-edge-delay.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-edge-delay.R b/tests/testthat/test-edge-delay.R index 003ce81f..ce37680f 100644 --- a/tests/testthat/test-edge-delay.R +++ b/tests/testthat/test-edge-delay.R @@ -19,7 +19,8 @@ DT[, datetime := as.POSIXct(datetime, tz = 'UTC')] group_times(DT, datetime = datetime, threshold = timethreshold) direction_step(DT, id, coords, projection) edges <- edge_dist(DT, threshold = threshold, id = id, - timegroup = timegroup, returnDist = TRUE, fillNA = FALSE) + coords = coords, timegroup = timegroup, + returnDist = TRUE, fillNA = FALSE) dyad_id(edges, id1 = 'ID1', id2 = 'ID2') fusion_id(edges, threshold = threshold) From 90bc8ed88563b547f2b44b10e0f74d08957c64a2 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 20:04:30 -0400 Subject: [PATCH 37/42] fix use copy edges/dt --- tests/testthat/test-edge-delay.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-edge-delay.R b/tests/testthat/test-edge-delay.R index ce37680f..267928ac 100644 --- a/tests/testthat/test-edge-delay.R +++ b/tests/testthat/test-edge-delay.R @@ -52,17 +52,17 @@ test_that('column names must exist in DT', { copy_edges <- copy(clean_edges) copy_edges[, timegroup := NULL] - expect_error(edge_delay(edges, DT, id = id), + expect_error(edge_delay(copy_edges, DT, id = id, window = window), 'timegroup field') copy_edges <- copy(clean_edges) copy_edges[, fusionID := NULL] - expect_error(edge_delay(edges, DT, id = id), + expect_error(edge_delay(copy_edges, DT, id = id, window = window), 'fusionID field') copy_edges <- copy(clean_edges) copy_edges[, dyadID := NULL] - expect_error(edge_delay(edges, DT, id = id), + expect_error(edge_delay(copy_edges, DT, id = id, window = window), 'dyadID field') expect_error(edge_delay(edges, DT, id = id, direction = 'potato'), @@ -70,7 +70,7 @@ test_that('column names must exist in DT', { copy_DT <- copy(clean_DT) copy_DT[, timegroup := NULL] - expect_error(edge_delay(edges, DT, id = id), + expect_error(edge_delay(edges, copy_DT, id = id, window = window), 'timegroup field') }) From 116dab6cf33ad1e20922017e0ac9724de47ca352 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 20:04:40 -0400 Subject: [PATCH 38/42] fix len to match expected output cols --- tests/testthat/test-edge-delay.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-edge-delay.R b/tests/testthat/test-edge-delay.R index 267928ac..7b7004a4 100644 --- a/tests/testthat/test-edge-delay.R +++ b/tests/testthat/test-edge-delay.R @@ -82,7 +82,8 @@ test_that('no rows are added to the result edges', { test_that('two columns added to the result DT', { copyEdges <- copy(edges) - expect_equal(ncol(copyEdges) + 1, + expect_equal(length(c('ID1', 'ID2', 'timegroup', + 'dyadID', 'fusionID', 'dir_corr_delay')), ncol(edge_delay(edges, DT, id = id, window = window))) }) From 86c2b969f1dfe0bda6b24435aafc8364dde30c8d Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 20:04:50 -0400 Subject: [PATCH 39/42] fix integer returned --- tests/testthat/test-edge-delay.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-edge-delay.R b/tests/testthat/test-edge-delay.R index 7b7004a4..b32bae99 100644 --- a/tests/testthat/test-edge-delay.R +++ b/tests/testthat/test-edge-delay.R @@ -87,8 +87,8 @@ test_that('two columns added to the result DT', { ncol(edge_delay(edges, DT, id = id, window = window))) }) -test_that('column added to the result DT is double', { - expect_type(edge_delay(edges, DT, id = id, window = window)$dir_corr_delay, 'double') +test_that('column added to the result DT is integer', { + expect_type(edge_delay(edges, DT, id = id, window = window)$dir_corr_delay, 'integer') }) test_that('returns a data.table', { From 2f67e07623acadb70de21dace4ae36becd6557dd Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 20:04:58 -0400 Subject: [PATCH 40/42] fix potato field --- tests/testthat/test-edge-delay.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-edge-delay.R b/tests/testthat/test-edge-delay.R index b32bae99..064e42de 100644 --- a/tests/testthat/test-edge-delay.R +++ b/tests/testthat/test-edge-delay.R @@ -65,8 +65,9 @@ test_that('column names must exist in DT', { expect_error(edge_delay(copy_edges, DT, id = id, window = window), 'dyadID field') - expect_error(edge_delay(edges, DT, id = id, direction = 'potato'), - 'direction field') + expect_error(edge_delay(edges, DT, id = id, window = window, + direction = 'potato'), + 'potato field') copy_DT <- copy(clean_DT) copy_DT[, timegroup := NULL] From 39fc13643086ba4b9eb4e00aa9096776ec1db2bd Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 20:05:18 -0400 Subject: [PATCH 41/42] fix make consistent error msg --- R/edge_delay.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/edge_delay.R b/R/edge_delay.R index bb05a702..b3a3c629 100644 --- a/R/edge_delay.R +++ b/R/edge_delay.R @@ -136,11 +136,11 @@ edge_delay <- function( } if (!'fusionID' %in% colnames(edges)) { - stop('fusionID not present in edges, did you run fusion_id?') + stop('fusionID field not present in edges, did you run fusion_id?') } if (!'dyadID' %in% colnames(edges)) { - stop('dyadID not present in edges, did you run dyad_id?') + stop('dyadID field not present in edges, did you run dyad_id?') } From 68d9221e25ca2eb27cd525f27ee941cdae125b50 Mon Sep 17 00:00:00 2001 From: "Alec L. Robitaille" Date: Tue, 19 Nov 2024 20:16:00 -0400 Subject: [PATCH 42/42] todo expected tests --- tests/testthat/test-edge-delay.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-edge-delay.R b/tests/testthat/test-edge-delay.R index 064e42de..b98b3a72 100644 --- a/tests/testthat/test-edge-delay.R +++ b/tests/testthat/test-edge-delay.R @@ -96,3 +96,4 @@ test_that('returns a data.table', { expect_s3_class(edge_delay(edges, DT, id = id, window = window), 'data.table') }) +# TODO: expected results tests