ape (version 5.2)

updateLabel: Update Labels

Description

This function changes labels (names or rownames) giving two vectors (old and new). It is a generic function with several methods as described below.

Usage

updateLabel(x, old, new, ...)
# S3 method for character
updateLabel(x, old, new, exact = TRUE, ...)
# S3 method for DNAbin
updateLabel(x, old, new, exact = TRUE, ...)
# S3 method for AAbin
updateLabel(x, old, new, exact = TRUE, ...)
# S3 method for phylo
updateLabel(x, old, new, exact = TRUE, nodes = FALSE, ...)
# S3 method for evonet
updateLabel(x, old, new, exact = TRUE, nodes = FALSE, ...)
# S3 method for data.frame
updateLabel(x, old, new, exact = TRUE, ...)
# S3 method for matrix
updateLabel(x, old, new, exact = TRUE, ...)

Arguments

x

an object where to change the labels.

old, new

two vectors of mode character (must be of the same length).

exact

a logical value (see details).

nodes

a logical value specifying whether to also update the node labels of the tree or network.

further arguments passed to and from methods.

Value

an object of the same class than x.

Details

This function can be used to change some of the labels (see examples) or all of them if their ordering is not sure.

If exact = TRUE (the default), the values in old are matched exactly with the labels; otherwise (exact = FALSE), the values in old are considered as regular expressions and searched in the labels with grep.

See Also

makeLabel, makeNodeLabel, mixedFontLabel, stripLabel

Examples

Run this code
# NOT RUN {
## the tree by Nyakatura & Bininda-Emonds (2012, BMC Biology)
x <- "https://static-content.springer.com/esm/art"
y <- "3A10.1186"
z <- "2F1741-7007-10-12/MediaObjects/12915_2011_534_MOESM5_ESM.NEX"
## The commande below may not print correctly in HTML because of the
## percentage symbol; see the text or PDF help page.
url <- paste(x, y, z, sep = "<!-- %") -->
TC <- read.nexus(url)
tr <- TC$carnivoreST_bestEstimate
old <- c("Uncia_uncia", "Felis_manul", "Leopardus_jacobitus")
new <- c("Panthera_uncia", "Otocolobus_manul", "Leopardus_jacobita")
tr.updated <- updateLabel(tr, old, new)
# }
# NOT RUN {
tr <- rtree(6)
## the order of the labels are randomized by this function
old <- paste0("t", 1:6)
new <- paste0("x", 1:6)
updateLabel(tr, old, new)
tr
# }

Run the code above in your browser using DataCamp Workspace