Set tip and internal node labels in a tree

PCMTreeSetLabels(
  tree,
  labels = as.character(1:PCMTreeNumNodes(tree)),
  inplace = TRUE
)

Arguments

tree

a phylo object or a PCMTree object. If this is a PCMTree object, the internal edge.part and part.regime members will be updated accordingly.

labels

a character vector in the order 1:PCMTreeNumNodes(tree) as denoted in the tree$edge matrix.

inplace

a logical indicating if the change should be done in place on the object in the calling environment (in this case tree must not be a temporary object, e.g. returned by another function call). Default is TRUE.

Value

if inplace is FALSE, a copy of tree with set or modified tree$tip.label and tree$node.label. If the original tree has a member edge.part, the returned tree has tree$edge.part and tree$part.regime updated. If inplace is TRUE (the default), nothing is returned and the above changes are made directly on the input tree.

See also

Examples

tree <- ape::rtree(5) tree$tip.label
#> [1] "t2" "t5" "t1" "t4" "t3"
# the following three are NULLs tree$node.label
#> NULL
tree$edge.part
#> NULL
tree$part.regime
#> NULL
tree <- PCMTree(tree) PCMTreeSetPartition(tree, c(6, 8)) tree$tip.label
#> [1] "t2" "t5" "t1" "t4" "t3"
tree$node.label
#> [1] "6" "7" "8" "9"
tree$edge.part
#> [1] "6" "6" "8" "8" "8" "6" "6" "6"
tree$part.regime
#> 6 8 #> 1 2
PCMTreeSetLabels( tree, labels = paste0(c(rep("t", 5), rep("n", 4)), PCMTreeGetLabels(tree))) PCMTreeGetLabels(tree)
#> [1] "tt2" "tt5" "tt1" "tt4" "tt3" "n6" "n7" "n8" "n9"
tree$tip.label
#> [1] "tt2" "tt5" "tt1" "tt4" "tt3"
tree$node.label
#> [1] "n6" "n7" "n8" "n9"
tree$edge.part
#> [1] "n6" "n6" "n8" "n8" "n8" "n6" "n6" "n6"
tree$part.regime
#> n6 n8 #> 1 2