[Phylobase-commits] r445 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 25 23:49:54 CEST 2009


Author: regetz
Date: 2009-06-25 23:49:54 +0200 (Thu, 25 Jun 2009)
New Revision: 445

Modified:
   pkg/R/class-phylo4d.R
   pkg/man/phylo4d.Rd
Log:
added option to phylo4d("phylo") method to drop node labels altogether
or convert them to (numeric) tree data; updated documentation to match


Modified: pkg/R/class-phylo4d.R
===================================================================
--- pkg/R/class-phylo4d.R	2009-06-25 20:12:15 UTC (rev 444)
+++ pkg/R/class-phylo4d.R	2009-06-25 21:49:54 UTC (rev 445)
@@ -124,8 +124,29 @@
 })
 
 ## first arg is a phylo
-setMethod("phylo4d", c("phylo"), function(x, tip.data=NULL, node.data=NULL, all.data=NULL, ...){
-    tree <- as(x, "phylo4")
+setMethod("phylo4d", c("phylo"), function(x, tip.data=NULL,
+    node.data=NULL, all.data=NULL, check.node.labels=c("keep", "drop",
+    "asdata"), ...) {
+
+    check.node.labels <- match.arg(check.node.labels)
+    if (check.node.labels == "asdata") {
+        # FIXME? use.node.names=TRUE won't work with this option b/c
+        # node labels are dropped; assumes node.data (if any), phylo
+        # node.label, and phylo4 internal nodes are in the same order?
+        nlab.data <- x$node.label
+        x$node.label <- NULL
+        nlab.data[!nzchar(nlab.data)] <- NA
+        # TODO only convert to numeric if values are number-like?
+        nlab.data <- data.frame(labelValues=as.numeric(nlab.data))
+        if (is.null(node.data)) {
+            node.data <- nlab.data
+        } else {
+            node.data <- cbind(nlab.data, node.data)
+        }
+        tree <- phylo4(x, check.node.labels="drop")
+    } else {
+        tree <- phylo4(x, check.node.labels=check.node.labels)
+    }
     res <- phylo4d(tree, tip.data, node.data, all.data, ...)
     return(res)
 })

Modified: pkg/man/phylo4d.Rd
===================================================================
--- pkg/man/phylo4d.Rd	2009-06-25 20:12:15 UTC (rev 444)
+++ pkg/man/phylo4d.Rd	2009-06-25 21:49:54 UTC (rev 445)
@@ -27,7 +27,8 @@
      \S4method{phylo4d}{phylo4}(x, tip.data = NULL, node.data = NULL,
         all.data = NULL, merge.tip.node = TRUE, ...)
      \S4method{phylo4d}{phylo}(x, tip.data = NULL, node.data = NULL,
-        all.data = NULL, merge.tip.node = TRUE, ...)
+        all.data = NULL, merge.tip.node = TRUE,
+        check.node.labels = c("keep", "drop", "asdata"), ...)
      \S4method{phylo4d}{matrix}(x, tip.data = NULL, node.data = NULL,
         all.data = NULL, merge.tip.node = TRUE, ...)
 }
@@ -43,6 +44,12 @@
     provided, it determines if they should be merged as a single
     trait. This argument is evaluated only if both \code{tip.data} and
     \code{node.data} have identical column names.}
+  \item{check.node.labels}{if \code{x} is of class \code{phylo}, use
+    either "keep" (the default) to retain internal node labels, "drop"
+    to drop them, or "asdata" to convert them to numeric tree data. This
+    argument is useful if the \code{phylo} object has non-unique node
+    labels or node labels with informative data (e.g., posterior
+    probabilities).}
   \item{\dots}{further arguments to be passed to other methods. Used to
     control the validity checking of the created object (see \code{\link{checkData}}).}
 }



More information about the Phylobase-commits mailing list