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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TreeTools 2.0.0.9006 (development) #
- `FirstMatchingSplit()`...
- Support logical `pole` in `PolarizeSplits()`.
- `RenumberTree()` supports numeric `tipOrder` input.

# TreeTools 2.0.0.9004 (development) #
- Support larger trees in `ClusterTable` objects.
Expand Down
11 changes: 8 additions & 3 deletions R/tree_numbering.R
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,9 @@ TntOrder.NULL <- function(tree) NULL
#'
#' @template treeParam
#' @param tipOrder A character vector containing the values of
#' `tree[["tip.label"]]` in the desired sort order, or an object
#' (perhaps of class `phylo` or `Splits`) with tip labels.
#' `tree[["tip.label"]]` in the desired sort order,
#' an object (perhaps of class `phylo` or `Splits`) with tip labels,
#' or a numeric specifying the desired order.
#'
#' @return `RenumberTips()` returns `tree`, with the tips' internal
#' representation numbered to match `tipOrder`.
Expand All @@ -604,7 +605,11 @@ RenumberTips <- function(tree, tipOrder) UseMethod("RenumberTips")
#' @export
RenumberTips.phylo <- function(tree, tipOrder) {
startOrder <- tree[["tip.label"]]
newOrder <- TipLabels(tipOrder, single = TRUE)
newOrder <- if (is.numeric(tipOrder)) {
startOrder[tipOrder]
} else {
TipLabels(tipOrder, single = TRUE)
}
if (!identical(startOrder, newOrder)) {
if (length(startOrder) != length(newOrder)) {
startOnly <- setdiff(startOrder, newOrder)
Expand Down
5 changes: 3 additions & 2 deletions man/RenumberTips.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/testthat/test-tree_numbering.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ test_that("RenumberTree() fails safely", {
expect_error(RenumberTree(1:4, 1:4, 5:6))
})

test_that("RenumberTree() with numeric tipOrder", {
tr <- BalancedTree(6)
order <- c(6, 5, 4, 2, 3, 1)
expect_equal(RenumberTips(tr, order), RenumberTips(tr, TipLabels(order)))
})

test_that("RenumberTree() handles polytomies", {
tr <- ape::read.tree(text = "(a, (b, d, c));")
edge <- tr$edge
Expand Down
Loading