+
+as.network.phylo <- function(x, directed = is.rooted(x), ...)
+{
+ if (is.null(x$node.label)) x <- makeNodeLabel(x)
+ res <- network(x$edge, directed = directed, ...)
+ network.vertex.names(res) <- c(x$tip.label, x$node.label)
+ res
+}
+
+as.igraph <- function(x, ...) UseMethod("as.igraph")
+
+as.igraph.phylo <- function(x, directed = is.rooted(x), use.labels = TRUE, ...)
+{
+ ## local copy because x will be changed before evaluating is.rooted(x):
+ directed <- directed
+ if (use.labels) {
+ if (is.null(x$node.label)) x <- makeNodeLabel(x)
+ x$edge <- matrix(c(x$tip.label, x$node.label)[x$edge], ncol = 2)
+ } else x$edge <- x$edge - 1L
+ graph.edgelist(x$edge, directed = directed, ...)
+}