This function iteratively removes specified tips (or tips matching a pattern) from a phylogenetic tree without collapsing internal nodes or singleton nodes.

drop_tips_update(tr, drop_name, pattern = NULL)

Arguments

tr

A phylogenetic tree of class phylo.

drop_name

A character vector of tip or node names to drop. If missing and pattern is provided, names matching the pattern will be dropped.

pattern

An optional regular expression pattern to match tip or node labels for dropping.

Value

A phylo object with specified tips removed.

Examples

if (requireNamespace("ape")) {
  library(ape)
  tr <- rtree(10)
  plot(tr)
  # Drop tips containing "t1" or "t2" in their label
  tr2 <- drop_tips_update(tr, pattern = "t1|t2")
  plot(tr2)

  # Alternatively, specify tips directly
  tr3 <- drop_tips_update(tr, drop_name = c("t3", "t5"))
  plot(tr3)
}
#> Loading required namespace: ape