1 ## is.binary.tree.R (2002-09-12) [modified by EP 2005-05-31, 2005-08-18,
4 ## Tests whether a given phylogenetic tree is binary
6 ## Copyright 2002 Korbinian Strimmer
8 ## This file is part of the R-package `ape'.
9 ## See the file ../COPYING for licensing issues.
11 is.binary.tree <- function(phy)
13 if (class(phy) != "phylo") stop('object "phy" is not of class "phylo"')
14 ## modified by EP so that it works without edge lengths too (2005-05-31):
15 nb.tip <- length(phy$tip.label)
17 ## modified by EP so that it works with both rooted and unrooted
18 ## trees (2005-08-18):
20 if (nb.tip - 1 == nb.node) return(TRUE)
23 if (nb.tip - 2 == nb.node) return(TRUE)