apply_duplicate_suffixes: Apply duplicate suffixes to tips and nodes

View source: R/labels.R

apply_duplicate_suffixesR Documentation

Apply duplicate suffixes to tips and nodes

Description

Suffixes are applied to ensure tip labels and node labels are not duplicates. Suffixes have the form -1, -2, -3, ...

Usage

apply_duplicate_suffixes(phy)

Arguments

phy

A phylo object, the tree whose labels are to have copy suffixes applied.

Details

The function recognizes existing duplicate suffixes and deals with them in one of two ways. If a label has n duplicates that are already suffixed -1, -2, ... -n, then the suffixes are not changed. Under any other conditions, old suffixes are removed and new ones applied.

Suffixation of tips and of nodes are handled independently of one another.

Value

A phylo object, the same tree but with suffixes applied to the labels.

Examples


library(ape)

tree <- abridge_labels(get_glottolog_trees("Koreanic"))
plot_glotto(tree)
tree2 <- clone_tip(tree, "chol1278", n = 2, subgroup = TRUE)
plot_glotto(tree2)
# Technically, tree2 is ill-formed because it has duplicate tip labels.
# Note how this causes problems if we try to clone one of them, since it
# is unclear which should be cloned:
## Not run: 
tree2a <- clone_tip(tree2, "chol1278")

## End(Not run)

# Suffixation of duplicate tips
tree3 <- apply_duplicate_suffixes(tree2)
plot_glotto(tree3)

# Once they are suffixed, these tips can be cloned successfully:
tree4 <- clone_tip(tree3, c("chol1278-2", "chol1278-3"), subgroup = TRUE)
plot_glotto(tree4)
# Suffixing is applied across all tips that share a glottocode, and
# separately, across all nodes that share a glottocode:
tree5 <- apply_duplicate_suffixes(tree4)
plot_glotto(tree5)

erichround/glottoTrees documentation built on April 17, 2025, 10:47 a.m.