Learn R Programming

phylobase (version 0.6.8)

phylo4-labels: Labels for phylo4/phylo4d objects

Description

Methods for creating, accessing and updating labels in phylo4/phylo4d objects

Usage

## S3 method for class 'phylo4':
labels(object, type=c("all", "tip", "internal"))
## S3 method for class 'phylo4,ANY,ANY,character':
labels(x, type=c("all", "tip",
  "internal"), use.names=FALSE) <- value

## S3 method for class 'phylo4': hasDuplicatedLabels(x, type=c("all", "tip", "internal"))

## S3 method for class 'phylo4': tipLabels(x) ## S3 method for class 'phylo4,character': tipLabels(x) <- value

## S3 method for class 'phylo4': hasNodeLabels(x) ## S3 method for class 'phylo4': nodeLabels(x) ## S3 method for class 'phylo4,character': nodeLabels(x) <- value

## S3 method for class 'phylo4': hasEdgeLabels(x) ## S3 method for class 'phylo4': edgeLabels(x) ## S3 method for class 'phylo4,character': edgeLabels(x) <- value

Arguments

x
a phylo4 or phylo4d object.
object
a phylo4 or phylo4d object.
type
which type of labels: all (tips and internal nodes), tip (tips only), internal (internal nodes only).
value
a vector of class character, see Details for more information.
use.names
should the names of the vector used to create/update labels be used to match the labels? See Details for more information.

Details

In phylo4/phylo4d objects, tips must have labels (that's why there is no method for hasTipLabels), internal nodes and edges can have labels.

Labels must be provided as a vector of class character. The length of the vector must match the number of elements they label.

The option use.names allows the user to match a label to a particular node. In this case, the vector must have names that match the node numbers.

The function labels is mostly intended to be used internally.

Examples

Run this code
data(geospiza)

## Return labels from geospiza
tipLabels(geospiza)

## Internal node labels in geospiza are empty
nodeLabels(geospiza)

## Creating internal node labels
ndLbl <- paste("n", 1:nNodes(geospiza), sep="")
nodeLabels(geospiza) <- ndLbl
nodeLabels(geospiza)

## naming the labels
names(ndLbl) <- nodeId(geospiza, "internal")

## shuffling the labels
(ndLbl <- sample(ndLbl))

## by default, the labels are attributed in the order
## they are given:
nodeLabels(geospiza) <- ndLbl
nodeLabels(geospiza)

## but use.names puts them in the correct order
labels(geospiza, "internal", use.names=TRUE) <- ndLbl
nodeLabels(geospiza)

Run the code above in your browser using DataLab