+
+ ## find the new terminal edges (works whatever 'subtree' and 'trim.internal'):
+ TERMS <- !(phy$edge[, 2] %in% phy$edge[, 1])
+
+ ## get the old No. of the nodes and tips that become tips:
+ oldNo.ofNewTips <- phy$edge[TERMS, 2]
+
+ ## in case some tips are dropped but kept because of 'subtree = TRUE':
+ if (subtree) {
+ i <- which(tip %in% oldNo.ofNewTips)
+ if (length(i)) {
+ phy$tip.label[tip[i]] <- "[1_tip]"
+ tip <- tip[-i]
+ }
+ }
+
+ n <- length(oldNo.ofNewTips) # the new number of tips in the tree
+
+ ## the tips may not be sorted in increasing order in the
+ ## 2nd col of edge, so no need to reorder $tip.label
+ phy$edge[TERMS, 2] <- rank(phy$edge[TERMS, 2])