+ phy <- reorder(phy)
+
+ ## the node numbers are not in increasing order in edge[, 2]: this
+ ## will confuse drop.tip and other functions (root), so renumber them
+ newNb <- integer(phy$Nnode)
+ newNb[1] <- n + 1L
+ sndcol <- phy$edge[, 2] > n
+
+ ## reorder node labels before changing edge:
+ if (!is.null(phy$node.label)) {
+ o <- 1 + rank(phy$edge[sndcol, 2])
+ ## the root's label is not changed:
+ phy$node.label <- phy$node.label[c(1, o)]
+ }
+
+ ## executed from right to left, so newNb is modified before phy$edge:
+ phy$edge[sndcol, 2] <- newNb[phy$edge[sndcol, 2] - n] <-
+ n + 2:phy$Nnode
+ phy$edge[, 1] <- newNb[phy$edge[, 1] - n]
+ phy