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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Dec 18 15:52:05 CET 2008


Author: bbolker
Date: 2008-12-18 15:52:05 +0100 (Thu, 18 Dec 2008)
New Revision: 308

Modified:
   pkg/R/methods-phylo4.R
   pkg/R/phylo4.R
   pkg/man/nNodes-methods.Rd
Log:
  added capability to retrieve particular edge lengths:
edgeLength(x,which)



Modified: pkg/R/methods-phylo4.R
===================================================================
--- pkg/R/methods-phylo4.R	2008-12-18 04:09:28 UTC (rev 307)
+++ pkg/R/methods-phylo4.R	2008-12-18 14:52:05 UTC (rev 308)
@@ -63,10 +63,14 @@
     stop("not implemented yet")
 })
 
-setMethod("edgeLength", "phylo4", function(x) {
+setMethod("edgeLength", "phylo4", function(x,which) {
     if (!hasEdgeLength(x))
         NULL
-    else x at edge.length
+    else {
+      if (missing(which)) return(x at edge.length)
+      n <- getnodes(x,which)
+      return(x at edge.length[n])
+    }
 })
 
 setMethod("sumEdgeLength", "phylo4", function(phy, node) {

Modified: pkg/R/phylo4.R
===================================================================
--- pkg/R/phylo4.R	2008-12-18 04:09:28 UTC (rev 307)
+++ pkg/R/phylo4.R	2008-12-18 14:52:05 UTC (rev 308)
@@ -30,7 +30,7 @@
     standardGeneric("hasEdgeLength")
 })
 
-setGeneric("edgeLength", function(x) {
+setGeneric("edgeLength", function(x,...) {
     standardGeneric("edgeLength")
 })
 

Modified: pkg/man/nNodes-methods.Rd
===================================================================
--- pkg/man/nNodes-methods.Rd	2008-12-18 04:09:28 UTC (rev 307)
+++ pkg/man/nNodes-methods.Rd	2008-12-18 14:52:05 UTC (rev 308)
@@ -95,13 +95,21 @@
 \section{usage}{
   \S4method{tdata}{phylo4d}(x, which = "tip", \dots)
   \S4method{tdata<-}{phylo4d}(object, which = "tip", \dots, value)
+  \S4method{edgeLength}{phylo4}(x, which)
 }
 \arguments{
-  \item{which}{Which data to extract: "tip" (tips only), "node"
+  \item{which}{(tdata) which data to extract: "tip" (tips only), "node"
     (internal nodes only), "allnode" (tips and internal nodes), "edge"
-    (edges) }
+    (edges) (edgeLength) which edge lengths to extract (indexed by
+    descendant node)}
   \item{x}{a phylo4d object}
   \item{object}{a phylo4d object}
   \item{value}{a data frame}
 }
+\examples{
+data(geospiza)
+edgeLength(geospiza,5)
+edgeLength(geospiza,"olivacea")
+edgeLength(geospiza,5:7)
+}
 \keyword{methods}



More information about the Phylobase-commits mailing list