]> git.donarmstrong.com Git - ape.git/blob - R/is.binary.tree.R
various bug fixes
[ape.git] / R / is.binary.tree.R
1 ## is.binary.tree.R (2002-09-12) [modified by EP 2005-05-31, 2005-08-18,
2 ##                                2006-10-04, 2009-05-10]
3
4 ##    Tests whether a given phylogenetic tree is binary
5
6 ## Copyright 2002 Korbinian Strimmer
7
8 ## This file is part of the R-package `ape'.
9 ## See the file ../COPYING for licensing issues.
10
11 is.binary.tree <- function(phy)
12 {
13     if (!inherits(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)
16     nb.node <- phy$Nnode
17     ## modified by EP so that it works with both rooted and unrooted
18     ## trees (2005-08-18):
19     if (is.rooted(phy)) {
20         if (nb.tip - 1 ==  nb.node) return(TRUE)
21         else return(FALSE)
22     } else {
23         if (nb.tip - 2 ==  nb.node) return(TRUE)
24         else return(FALSE)
25     }
26 }