Skip to contents

Internal nodes left with a single descendant are collapsed (their branch lengths are summed), node labels are kept, and the result is rooted at the most recent common ancestor of the retained tips. Tips are kept in their original order regardless of the order of tips.

Usage

tree_subset(tree, tips, underscores = FALSE)

Arguments

tree

A phylo object, as returned from read_tree().

tips

A character, numeric, or logical vector of tips to keep.

underscores

When parsing the tree, should underscores be kept as is? By default they will be converted to spaces (unless the entire ID is quoted). Default FALSE

Value

A phylo object for the subtree.

See also

Other phylogeny: read_tree()

Examples

    library(rbiom)

    infile <- system.file("extdata", "newick.tre", package = "rbiom")
    tree <- read_tree(infile)
    tree
#> 
#> Phylogenetic tree with 20 tips and 19 internal nodes.
#> 
#> Tip labels:
#>   Pa5Bac29, AtlPorci, AciSp313, MxlBact8, MxlBacte, PseS1107, ...
#> 
#> Rooted; includes branch length(s).

    subtree <- tree_subset(tree, tips = head(tree$tip.label))
    subtree
#> 
#> Phylogenetic tree with 6 tips and 5 internal nodes.
#> 
#> Tip labels:
#>   Pa5Bac29, AtlPorci, AciSp313, MxlBact8, MxlBacte, PseS1107
#> 
#> Rooted; includes branch length(s).