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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: TreeTools
Title: Create, Modify and Analyse Phylogenetic Trees
Version: 2.1.0.9007
Version: 2.1.0.9008
Authors@R: c(
person("Martin R.", 'Smith', role = c("aut", "cre", "cph"),
email = "martin.smith@durham.ac.uk",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# TreeTools 2.1.0.9008 (2026-03-17) #

- `PhyDatToMatrix()` no longer crashes on zero-character `phyDat` objects
(e.g. from a star tree); returns a 0-column matrix with correct row names.
- `AddUnconstrained()` handles zero-character `phyDat` input gracefully.

# TreeTools 2.1.0.9007 (2026-03-13) #

- `duplicated.Splits()` uses hash-based O(n) de-duplication, replacing
Expand Down
4 changes: 4 additions & 0 deletions R/parse_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,10 @@ PhyDatToMatrix <- function(dataset, ambigNA = FALSE, inappNA = ambigNA,
}

at <- attributes(dataset)
if (at[["nr"]] == 0L) {
return(matrix(character(0), nrow = length(at[["names"]]), ncol = 0,
dimnames = list(at[["names"]], NULL)))
}
allLevels <- as.character(at[["allLevels"]])
if (inappNA) {
allLevels[allLevels == "-"] <- NA_character_
Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/test-ImposeConstraint.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
test_that("AddUnconstrained() handles zero-character phyDat", {
star <- ape::read.tree(text = "(a,b,c,d);")
empty_pd <- MatrixToPhyDat(t(as.matrix(star)))

# PhyDatToMatrix returns a correctly-dimensioned 0-column matrix
mat <- PhyDatToMatrix(empty_pd)
expect_equal(dim(mat), c(4L, 0L))
expect_equal(rownames(mat), c("a", "b", "c", "d"))

# AddUnconstrained returns 0-character phyDat with extra taxa
result <- AddUnconstrained(empty_pd, c("e", "f", "g"))
expect_s3_class(result, "phyDat")
expect_equal(names(result), c("a", "b", "c", "d", "e", "f", "g"))
expect_equal(attr(result, "nr"), 0L)

# asPhyDat = FALSE returns a 0-column matrix
result_mat <- AddUnconstrained(empty_pd, c("e", "f", "g"), asPhyDat = FALSE)
expect_equal(dim(result_mat), c(7L, 0L))
expect_equal(rownames(result_mat), c("a", "b", "c", "d", "e", "f", "g"))
})

test_that("AddUnconstrained() works", {
tips <- letters[1:9]
constraint <- StringToPhyDat("0000?1111 000111111 0000??110", tips, FALSE)
Expand Down
Loading