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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 16 22:15:46 CEST 2009


Author: regetz
Date: 2009-09-16 22:15:45 +0200 (Wed, 16 Sep 2009)
New Revision: 652

Modified:
   pkg/R/subset.R
   pkg/man/subset-methods.Rd
Log:
split both phylo4 and phylo4d '[' into new methods with finer grained
signatures, motivated by codoc mismatches (bug #650); also changed the
phylo4d '[' method to index on (and return) all data, not just tip data


Modified: pkg/R/subset.R
===================================================================
--- pkg/R/subset.R	2009-09-14 23:04:41 UTC (rev 651)
+++ pkg/R/subset.R	2009-09-16 20:15:45 UTC (rev 652)
@@ -67,36 +67,58 @@
 ###############
 # '[' operator
 ###############
-## phylo4
-setMethod("[", "phylo4", function(x, i, j, ..., drop=FALSE) {
-    if (missing(i)) i <- TRUE
-    if (is.logical(i)) {
-        i <- nodeId(x, "tip")[i]
-    } # else pass 'i' straight through to subset method
+
+## Consider using some combination of these for stricter argument
+## checking? Not implementing now because extra arguments are just
+## ignored, which is fairly common S4 method behavior:
+## * in "[" methods for phylo4:
+##    if (nargs()>2) stop("unused arguments")
+## * in "[" methods for both phylo4 and phylo4d:
+##    if (!missing(...)) stop("unused argument(s)")
+
+## phylo4 '[' methods
+setMethod("[", signature(x="phylo4", i="character", j="missing",
+    drop="missing"), function(x, i, j, ..., drop) {
     subset(x, tips.include=i)
 })
+setMethod("[", signature(x="phylo4", i="numeric", j="missing",
+    drop="missing"), function(x, i, j, ..., drop) {
+    subset(x, tips.include=i)
+})
+setMethod("[", signature(x="phylo4", i="logical", j="missing",
+    drop="missing"), function(x, i, j, ..., drop) {
+    subset(x, tips.include=nodeId(x, "tip")[i])
+})
+setMethod("[", signature(x="phylo4", i="missing", j="missing",
+    drop="missing"), function(x, i, j, ..., drop) {
+    x
+})
+## phylo4d '[' methods
+setMethod("[", signature(x="phylo4d", i="ANY", j="character",
+    drop="missing"), function(x, i, j, ..., drop) {
+    if (!missing(i)) x <- x[i]
+    tdata(x, type="allnode") <- tdata(x, type="allnode")[j]
+    return(x)
+})
+setMethod("[", signature(x="phylo4d", i="ANY", j="numeric",
+    drop="missing"), function(x, i, j, ..., drop) {
+    if (!missing(i)) x <- x[i]
+    tdata(x, type="allnode") <- tdata(x, type="allnode")[j]
+    return(x)
+})
+setMethod("[", signature(x="phylo4d", i="ANY", j="logical",
+    drop="missing"), function(x, i, j, ..., drop) {
+    if (!missing(i)) x <- x[i]
+    tdata(x, type="allnode") <- tdata(x, type="allnode")[j]
+    return(x)
+})
+## borrow from Matrix package approach of trapping invalid usage
+setMethod("[", signature(x="phylo4", i="ANY", j="ANY", drop="ANY"),
+    function(x, i, j, ..., drop) {
+    stop("invalid argument(s)")
+})
 
-## phylo4d
-setMethod("[","phylo4d", 
-          function(x, i, j, ..., drop=FALSE) {
 
-              if(missing(i)) i <- TRUE
-              if(missing(j)) j <- TRUE
-
-              #### data handling
-              ## for now handle only tip data - assumes tip names are good row.names
-              tab <- tdata(x, type="tip")[i, j, ..., drop=FALSE]
-              
-              #### tree handling
-              tip.include <- match(row.names(tab), x at tip.label)
-              tre <- subset(as(x,"phylo4"), tips.include=tip.include)
-
-              ## result
-              res <- phylo4d(x=tre, tip.data=tab)
-              
-              return(res)
-          })
-
 ## extract the phylo4 part of phylo4d; relies on implicit coerce method
 extractTree <- function(from) {
     as(from, "phylo4")

Modified: pkg/man/subset-methods.Rd
===================================================================
--- pkg/man/subset-methods.Rd	2009-09-14 23:04:41 UTC (rev 651)
+++ pkg/man/subset-methods.Rd	2009-09-16 20:15:45 UTC (rev 652)
@@ -9,7 +9,16 @@
 \alias{prune,phylo4d-method}
 \alias{[-methods}
 \alias{[,phylo4-method}
+\alias{[,phylo4,character,missing,missing-method}
+\alias{[,phylo4,numeric,missing,missing-method}
+\alias{[,phylo4,logical,missing,missing-method}
+\alias{[,phylo4,missing,missing,missing-method}
 \alias{[,phylo4d-method}
+\alias{[,phylo4d,ANY,character,missing-method}
+\alias{[,phylo4d,ANY,numeric,missing-method}
+\alias{[,phylo4d,ANY,logical,missing-method}
+\alias{[,phylo4d,ANY,missing,missing-method}
+\alias{[,phylo4,ANY,ANY,ANY-method}
 \alias{na.omit,phylo4d-method}
 \title{Methods for creating subsets of phylogenies}
 \description{



More information about the Phylobase-commits mailing list