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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jun 29 03:17:41 CEST 2008


Author: bbolker
Date: 2008-06-29 03:17:41 +0200 (Sun, 29 Jun 2008)
New Revision: 192

Modified:
   pkg/R/methods-phylo4d.R
   pkg/R/phylo4.R
   pkg/R/treewalk.R
   pkg/man/nNodes-methods.Rd
Log:
added tdata<- method
tweaked one error message about mismatch in node and tip colnames
corrected "siblings" function




Modified: pkg/R/methods-phylo4d.R
===================================================================
--- pkg/R/methods-phylo4d.R	2008-06-22 04:33:06 UTC (rev 191)
+++ pkg/R/methods-phylo4d.R	2008-06-29 01:17:41 UTC (rev 192)
@@ -16,6 +16,27 @@
         x at node.data))
 })
 
+setMethod("tdata<-", "phylo4d", function(object, which = c("tip", 
+    "node", "allnode"), ..., value) {
+    which <- match.arg(which)
+    if (which == "allnode") {
+        namesmatch <- all(colnames(object at tip.data) == colnames(object at node.data))
+        classmatch <- all(sapply(object at tip.data, class) == sapply(object at node.data, 
+            class))
+        if (!(classmatch && namesmatch)) 
+            stop("Node and tip columns do not match;",
+                 "you should access tip and node data separately")
+    }
+    switch(which,
+           ## FIXME: add checks for matching row names etc ...
+           tip = object at tip.data <- value,
+           node = object at node.data <- value,
+           allnode = stop("for now, must set tip and node data separately"))
+    object
+})
+
+
+
 ## Alternative phylo4d summary method, using phylo4 summary
 ## Marguerite Butler & Peter Cowan
 setMethod("summary", "phylo4d", function(object) {

Modified: pkg/R/phylo4.R
===================================================================
--- pkg/R/phylo4.R	2008-06-22 04:33:06 UTC (rev 191)
+++ pkg/R/phylo4.R	2008-06-29 01:17:41 UTC (rev 192)
@@ -72,6 +72,10 @@
     standardGeneric("tdata")
 })
 
+setGeneric("tdata<-", function(object,...,value) {
+    standardGeneric("tdata<-")
+})
+
 setGeneric("hasNodeData", function(x) {
     standardGeneric("hasNodeData")
 })

Modified: pkg/R/treewalk.R
===================================================================
--- pkg/R/treewalk.R	2008-06-22 04:33:06 UTC (rev 191)
+++ pkg/R/treewalk.R	2008-06-29 01:17:41 UTC (rev 192)
@@ -75,7 +75,7 @@
 }
 
 siblings <- function(phy, node, include.self=FALSE) {
-    v <- children(phy,parent(phy,node))
+    v <- children(phy,ancestor(phy,node))
     if (!include.self) v <- v[v!=getnodes(phy,node)]
     v
 }

Modified: pkg/man/nNodes-methods.Rd
===================================================================
--- pkg/man/nNodes-methods.Rd	2008-06-22 04:33:06 UTC (rev 191)
+++ pkg/man/nNodes-methods.Rd	2008-06-29 01:17:41 UTC (rev 192)
@@ -54,10 +54,11 @@
 \alias{edgeLabels-methods}
 \alias{edgeLabels,phylo4-method}
 \alias{edgeLabels<-,phylo4-method}
-
 \alias{tdata}
+\alias{tdata<-}
 \alias{tdata-methods}
 \alias{tdata,phylo4d-method}
+\alias{tdata<-,phylo4d-method}
 \title{Methods for S4 phylogeny classes}
 \description{
    Generic methods for phylogenetic trees represented as S4 classes
@@ -93,10 +94,14 @@
 }
 \section{usage}{
   \S4method{tdata}{phylo4d}(x, which = "tip", \dots)
+  \S4method{tdata<-}{phylo4d}(object, which = "tip", \dots, value)
 }
 \arguments{
   \item{which}{Which data to extract: "tip" (tips only), "node"
     (internal nodes only), "allnode" (tips and internal nodes), "edge"
     (edges) }
+  \item{x}{a phylo4d object}
+  \item{object}{a phylo4d object}
+  \item{value}{a data frame}
 }
 \keyword{methods}



More information about the Phylobase-commits mailing list