[Phylobase-commits] r614 - in pkg: R inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 3 00:53:00 CEST 2009


Author: regetz
Date: 2009-09-03 00:52:59 +0200 (Thu, 03 Sep 2009)
New Revision: 614

Modified:
   pkg/R/treewalk.R
   pkg/inst/unitTests/runit.treewalk.R
Log:
fixed descendants to return tip ID with label as name, rather than the
reverse (bug #626); created descendants unit tests.


Modified: pkg/R/treewalk.R
===================================================================
--- pkg/R/treewalk.R	2009-09-02 19:01:46 UTC (rev 613)
+++ pkg/R/treewalk.R	2009-09-02 22:52:59 UTC (rev 614)
@@ -70,7 +70,7 @@
     node <- getNode(phy,node)
     if (is.na(node)) stop("node ",node," not found in tree")
     n <- nTips(phy)
-    if (node <= n) return(labels(phy,"allnode")[node])
+    if (node <= n) return(node)
     l <- numeric()
     d <- children(phy, node)
     for (j in d) {

Modified: pkg/inst/unitTests/runit.treewalk.R
===================================================================
--- pkg/inst/unitTests/runit.treewalk.R	2009-09-02 19:01:46 UTC (rev 613)
+++ pkg/inst/unitTests/runit.treewalk.R	2009-09-02 22:52:59 UTC (rev 614)
@@ -59,6 +59,27 @@
 
 test.descendants <- function() {
     # function (phy, node, type=c("tips","children","all"))
+    phy <- phylo4(read.tree(text="((t3,t4),(t1,(t2,t5)));"))
+
+    # node = tip
+    checkIdentical(descendants(phy, 5),
+        setNames(5L, "t5"))
+    checkIdentical(descendants(phy, 5, "tips"),
+        setNames(5L, "t5"))
+    checkIdentical(descendants(phy, 5, "children"),
+        setNames(integer(0), character(0)))
+    checkIdentical(descendants(phy, 5, "all"),
+        setNames(5L, "t5"))
+
+    # node = internal
+    checkIdentical(descendants(phy, 8),
+        setNames(c(3L, 4L, 5L), c("t1", "t2", "t5")))
+    checkIdentical(descendants(phy, 8, "tips"),
+        setNames(c(3L, 4L, 5L), c("t1", "t2", "t5")))
+    checkIdentical(descendants(phy, 8, "children"),
+        setNames(c(3L, 9L), c("t1", NA)))
+    checkIdentical(descendants(phy, 8, "all"),
+        setNames(c(3L, 9L, 4L, 5L), c("t1", NA, "t2", "t5")))
 }
 
 test.siblings <- function() {



More information about the Phylobase-commits mailing list