Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion R/fusion_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,14 @@ fusion_id <- function(
data.table::shift(within_dist, type = 'lead'),
by = dyadID
]

# If shift lead is fusion then shift id to lead id
unique_edges[, both_run := fifelse(
is_lead,
data.table::shift(both_run, type = 'lead'),
both_run
)]
),
by = dyadID]

# If n minimum length > 0, check nrows and return NA if less than min
if (n_min_length > 0) {
Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/test-fusion-id.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,24 @@ test_that('lead edge cases identified as expected', {
defaults_lead[, fusionID[timegroup == 6]])

})

test_that('max timegroup difference is not greater than expected', {
n_min_length <- 3
n_max_missing <- 1
allow_split <- TRUE

fusions <- fusion_id(
copy(edges),
50,
n_min_length = n_min_length,
n_max_missing = n_max_missing,
allow_split = allow_split
)
expect_all_false(
fusions[, max(timegroup - shift(timegroup), na.rm = TRUE), by = fusionID][,
V1 > (n_min_length + n_max_missing)]
)
})