+ i <- i + 1L
+ if (yHasNoRootEdge) {
+ j <- which(y$edge[, 1] == y$edge[1])
+ y$edge[j, 1] <- x$edge[i, 1]
+ } else y$edge[1] <- x$edge[i, 1]
+ } else {
+ if (yHasNoRootEdge) x$edge[i, 2] <- y$edge[1]
+ else {
+ ## the root edge of y is fused with the terminal edge of x
+ if (wbl) y$edge.length[1] <- y$edge.length[1] + x$edge.length[i]
+ y$edge[1] <- x$edge[i, 1]
+ ## delete i-th edge in x:
+ x$edge <- x$edge[-i, ]
+ if (wbl) x$edge.length <- x$edge.length[-i]
+ i <- i - 1L
+ }
+ x$tip.label <- x$tip.label[-where]
+ ## renumber the tips that need to:
+ ii <- which(x$edge[, 2] > where & x$edge[, 2] <= nx)
+ x$edge[ii, 2] <- x$edge[ii, 2] - 1L
+ }
+ x$edge <- rbind(x$edge[1:i, ], y$edge, x$edge[-(1:i), ])
+ if (wbl)
+ x$edge.length <- c(x$edge.length[1:i], y$edge.length, x$edge.length[-(1:i)])
+ }, { # case = 3
+ if (position) {
+ if (yHasNoRootEdge) {
+ j <- which(y$edge[, 1] == y$edge[1])
+ y$edge[j, 1] <- next.node
+ } else y$edge[1] <- next.node
+ x$edge <- rbind(x$edge[1:i, ], c(next.node, x$edge[i, 2]), x$edge[-(1:i), ])
+ x$edge[i, 2] <- next.node
+ if (wbl) {
+ x$edge.length[i] <- x$edge.length[i] - position
+ x$edge.length <- c(x$edge.length[1:i], position, x$edge.length[-(1:i)])