Skip to content

Commit

Permalink
Fix concatenation of unnamed list sample sets
Browse files Browse the repository at this point in the history
  • Loading branch information
bodkan committed Jul 27, 2023
1 parent abd8f8e commit b3c650e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/tree-sequences.R
Expand Up @@ -2971,6 +2971,8 @@ define_windows <- function(ts, breakpoints) {
concat <- function(x) {
if (is.list(x) && !is.null(names(x)))
return(names(x))
else if (is.list(x) && is.null(names(x)))
return(paste(x[[1]], collapse = "+"))
else
return(paste(x, collapse = "+"))
}
6 changes: 6 additions & 0 deletions tests/testthat/test-utililites.R
Expand Up @@ -14,3 +14,9 @@ test_that("distances beyond the world dimension throw and error", {
expect_silent(check_resolution(map, xrange / 10))
expect_silent(check_resolution(map, yrange / 10))
})

test_that("concat() function correctly collapses sample identifiers", {
expect_equal(concat(c("A", "B")), "A+B")
expect_equal(concat(list(c("A", "B"))), "A+B")
expect_equal(concat(list(xyz=c("A", "B"))), "xyz")
})

0 comments on commit b3c650e

Please sign in to comment.