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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 14 07:28:28 CEST 2009


Author: regetz
Date: 2009-09-14 07:28:28 +0200 (Mon, 14 Sep 2009)
New Revision: 649

Modified:
   pkg/R/subset.R
   pkg/man/subset-methods.Rd
Log:
simplified phylo4 '[' to deal with missing or logical index, but
otherwise pass arguments straight through to subset method


Modified: pkg/R/subset.R
===================================================================
--- pkg/R/subset.R	2009-09-14 04:21:08 UTC (rev 648)
+++ pkg/R/subset.R	2009-09-14 05:28:28 UTC (rev 649)
@@ -68,26 +68,14 @@
 # '[' operator
 ###############
 ## phylo4
-setMethod("[","phylo4",
-          function(x, i, j, ..., drop=FALSE) {
+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
+    subset(x, tips.include=i)
+})
 
-              if(missing(i)) i <- TRUE
-
-              oldlab <- tipLabels(x)
-              if(is.character(i)){
-                  newlab <- i
-              } else {
-                  newlab <- oldlab[i]
-              }
-              tip.include <- match(newlab, oldlab)
-              res <- subset(x, tips.include=tip.include)
-
-              return(res)
-          })
-
-
-
-
 ## phylo4d
 setMethod("[","phylo4d", 
           function(x, i, j, ..., drop=FALSE) {
@@ -112,4 +100,4 @@
 ## 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 04:21:08 UTC (rev 648)
+++ pkg/man/subset-methods.Rd	2009-09-14 05:28:28 UTC (rev 649)
@@ -69,8 +69,10 @@
 
   The "[" operator, when used as \code{x[i]}, is similar to the
   \code{tips.include} form of \code{subset}.  However, the indices used
-  with this operator can also be logical, just like with a vector or a
-  matrix.  With a \linkS4class{phylo4d} object 'x', \code{x[i,j]}
+  with this operator can also be logical, in which case the
+  corresponding tips are assumed to be ordered as in \code{nodeId(x,
+  "tip")}, and recycling rules will apply (just like with a vector or a
+  matrix).  With a \linkS4class{phylo4d} object 'x', \code{x[i,j]}
   creates a subset of \code{x} taking \code{i} for a tip index and
   \code{j} for the index of data variables in \code{tdata(geospiza,
   "all")}.  Note that the second index is optional: \code{x[i, TRUE]},



More information about the Phylobase-commits mailing list