prune: Remove tree nodes by regular expression pattern matching.

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/prune.R

Description

"prune" takes an object of class "dendrogram" and removes all branches whose branch labels match a given regular expression.

Usage

1
prune(tree, pattern, keep = FALSE, ...)

Arguments

tree

an object of class "dendrogram".

pattern

a regular expression.

keep

logical indicating whether the nodes whose labels match the regular expression provided in "pattern" should be kept and the remainder discarded. Defaults to FALSE. Note that nodes without "label" attributes are ignored.

...

further arguments to be passed to grepl and gsub.

Details

This function recursively tests the "label" attribute of each dendrogram node (including non-leaf inner nodes if applicable) for the specified pattern, removing those that register a positive hit. Note that positive matching inner nodes are removed along with all of their sub-nodes, regardless of whether the "label" attributes of the sub-nodes match the pattern.

Value

Returns an object of class "dendrogram".

Author(s)

Shaun Wilkinson

See Also

The drop.tip function in the ape package performs a similar operation for objects of class "phylo". See regex for help with compiling regular expressions.

Examples

1
2
3
4
  x <- read.dendrogram(text = "(A:0.1,B:0.2,(C:0.3,D:0.4):0.5);")
  plot(x, horiz = TRUE)
  x <- prune(x, pattern = "^A$")
  plot(x, horiz = TRUE)

shaunpwilkinson/phylogram documentation built on Dec. 11, 2019, 11:36 p.m.