X-Git-Url: https://git.donarmstrong.com/?p=ape.git;a=blobdiff_plain;f=R%2Fdrop.tip.R;fp=R%2Fdrop.tip.R;h=e9bd5c037364f4f8e20604ac3aff8ae6755a7b16;hp=5b635f680f4459a579242dfc4fdf2c549d9b5f22;hb=da67dccb93d35408baa48b141fcda921772c8b9c;hpb=b9e04a6e6af3beda74b916eda00b42ac38875563 diff --git a/R/drop.tip.R b/R/drop.tip.R index 5b635f6..e9bd5c0 100644 --- a/R/drop.tip.R +++ b/R/drop.tip.R @@ -1,8 +1,8 @@ -## drop.tip.R (2011-11-21) +## drop.tip.R (2012-10-06) ## Remove Tips in a Phylogenetic Tree -## Copyright 2003-2011 Emmanuel Paradis +## Copyright 2003-2012 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -208,14 +208,10 @@ drop.tip <- phy$tip.label <- c(phy$tip.label, new.tip.label) } - ## update node.label if needed: - if (!is.null(phy$node.label)) - phy$node.label <- phy$node.label[sort(unique(phy$edge[, 1])) - Ntip] - phy$Nnode <- dim(phy$edge)[1] - n + 1L # update phy$Nnode ## The block below renumbers the nodes so that they conform - ## to the "phylo" format -- same as in root() + ## to the "phylo" format, same as in root() newNb <- integer(n + phy$Nnode) newNb[NEWROOT] <- n + 1L sndcol <- phy$edge[, 2] > n @@ -224,6 +220,10 @@ drop.tip <- (n + 2):(n + phy$Nnode) phy$edge[, 1] <- newNb[phy$edge[, 1]] storage.mode(phy$edge) <- "integer" + if (!is.null(phy$node.label)) { # update node.label if needed + newNb[is.na(newNb)] <- 0L + phy$node.label <- phy$node.label[order(newNb[newNb > 0])] + } collapse.singles(phy) }