- ## We remove one of the edges coming from the root, and
- ## eventually adding the branch length to the other one
- ## also coming from the root.
- ## In all cases, the node deleted is the 2nd one (numbered
- ## nb.tip+2 in 'edge'), so we simply need to renumber the
- ## nodes by adding 1, except the root (this remains the
- ## origin of the tree).
- nb.tip <- length(phy$tip.label)
- ROOT <- nb.tip + 1L
- EDGEROOT <- which(phy$edge[, 1] == ROOT)
- ## j: the target where to stick the edge
- ## i: the edge to delete
- if (phy$edge[EDGEROOT[1], 2] == ROOT + 1L) {
- j <- EDGEROOT[2]
- i <- EDGEROOT[1]
+
+ n <- length(phy$tip.label)
+ ROOT <- n + 1L
+
+### EDGEROOT[1]: the edge to delete
+### EDGEROOT[2]: the target where to stick the edge to delete
+
+### If the tree is in pruningwise order, then the last two edges
+### are those connected to the root; the node situated in
+### phy$edge[N - 2L, 1L] will be the new root...
+
+ ophy <- attr(phy, "order")
+ if (!is.null(ophy) && ophy == "pruningwise") {
+ NEWROOT <- phy$edge[N - 2L, 1L]
+ EDGEROOT <- c(N, N - 1L)