[Phylobase-commits] r325 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Dec 19 13:52:47 CET 2008
Author: francois
Date: 2008-12-19 13:52:47 +0100 (Fri, 19 Dec 2008)
New Revision: 325
Modified:
pkg/R/methods-phylo4.R
Log:
nTips now returns 0 on empty trees
Modified: pkg/R/methods-phylo4.R
===================================================================
--- pkg/R/methods-phylo4.R 2008-12-19 10:51:53 UTC (rev 324)
+++ pkg/R/methods-phylo4.R 2008-12-19 12:52:47 UTC (rev 325)
@@ -7,12 +7,16 @@
setMethod("nTips", "phylo4", function(x, ...) {
E <- edges(x)
- ## doesn't handle reticulated networks
- ## res <- sum(!E[, 2] %in% E[, 1])
- res <- sum(tabulate(E[,1]) == 0) ## twice as fast as ...
- ## change suggested by Aaron Mackey, handles reticulated networks better
- ## res <- sum(!(unique(E[,2]) %in% E[,1]))
- return(res)
+ if(nrow(E) == 0)
+ return(0)
+ else {
+ ## doesn't handle reticulated networks
+ ## res <- sum(!E[, 2] %in% E[, 1])
+ res <- sum(tabulate(E[,1]) == 0) ## twice as fast as ...
+ ## change suggested by Aaron Mackey, handles reticulated networks better
+ ## res <- sum(!(unique(E[,2]) %in% E[,1]))
+ return(res)
+ }
})
## hack to ensure ape compatibility
@@ -47,9 +51,9 @@
## HACK: make sure we find the right "nTips"
tabulate(edges(x)[, 1])[nTips(x) + 1] <= 2
## root node (first node after last tip) has <= 2 descendants
- ## FIXME (?): fails with empty tree
})
+
setMethod("rootNode", "phylo4", function(x) {
if (!isRooted(x))
return(NA)
More information about the Phylobase-commits
mailing list