[Phylobase-commits] r909 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Apr 8 19:39:20 CEST 2014


Author: francois
Date: 2014-04-08 19:39:20 +0200 (Tue, 08 Apr 2014)
New Revision: 909

Modified:
   pkg/R/root-methods.R
Log:
updated doc for root methods

Modified: pkg/R/root-methods.R
===================================================================
--- pkg/R/root-methods.R	2014-04-08 16:57:26 UTC (rev 908)
+++ pkg/R/root-methods.R	2014-04-08 17:39:20 UTC (rev 909)
@@ -1,5 +1,28 @@
 
+##' Methods to test, access (and modify) the root of a phylo4 object.
+##'
+##' @rdname root-methods
+##' @aliases isRooted
+##' @docType methods
+##' @param x a \code{phylo4} or \code{phylo4d} object.
+##' @param value a character string or a numeric giving the new root.
+##' @return \describe{
+##'   \item{isRooted}{logical whether the tree is rooted}
+##'   \item{rootNode}{the node corresponding to the root}
+##' }
+##' @include phylo4-class.R phylo4-methods.R phylo4-accessors.R
+##' @export
+##' @author Ben Bolker, Francois Michonneau
+##' @examples
+##' data(geospiza)
+##' isRooted(geospiza)
+##' rootNode(geospiza)
+setGeneric("isRooted", function(x) {
+    standardGeneric("isRooted")
+})
 
+##' @rdname root-methods
+##' @aliases isRooted,phylo4-method
 setMethod("isRooted", signature(x="phylo4"),
  function(x) {
     ## hack to avoid failure on an empty object
@@ -7,13 +30,30 @@
     any(edges(x)[, 1] == 0)
 })
 
+##' @rdname root-methods
+##' @aliases rootNode
+setGeneric("rootNode", function(x) {
+    standardGeneric("rootNode")
+})
+
+##' @rdname root-methods
+##' @aliases rootNode,phylo4-method
 setMethod("rootNode", signature(x="phylo4"),
  function(x) {
     if (!isRooted(x))
         return(NA)
-    unname(edges(x)[which(edges(x)[, 1] == 0), 2])
+    rootnd <- unname(edges(x)[which(edges(x)[, 1] == 0), 2])
+    getNode(x, rootnd)
 })
 
+##' @rdname root-methods
+##' @aliases rootNode<-
+setGeneric("rootNode<-", function(x, value) {
+    standardGeneric("rootNode<-")
+})
+
+##' @rdname root-methods
+##' @aliases rootNode<-,phylo4-method
 setReplaceMethod("rootNode", signature(x="phylo4"),
  function(x, value) {
     stop("Root node replacement not implemented yet")



More information about the Phylobase-commits mailing list