[Phylobase-commits] r118 - in pkg: R man tests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Feb 23 16:03:53 CET 2008


Author: jombart
Date: 2008-02-23 16:03:53 +0100 (Sat, 23 Feb 2008)
New Revision: 118

Modified:
   pkg/R/subset.R
   pkg/man/subset-methods.Rd
   pkg/tests/plottest.R
Log:
Implemented the "[" operator with phylo4 and phylo4d objects.
Put documentation in subset manpage.
Warnings to be fixed. 


Modified: pkg/R/subset.R
===================================================================
--- pkg/R/subset.R	2008-02-23 13:52:13 UTC (rev 117)
+++ pkg/R/subset.R	2008-02-23 15:03:53 UTC (rev 118)
@@ -46,3 +46,47 @@
 })
 
 
+
+
+###############
+# '[' operator
+###############
+## phylo4
+setMethod("[","phylo4", 
+          function(x, i) {
+
+              if(missing(i)) i <- TRUE
+
+              oldlab <- labels(x)
+              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) {
+
+              if(missing(i)) i <- TRUE
+              if(missing(j)) j <- TRUE
+
+              #### data handling
+              ## for now handle only tip data
+              tab <- tdata(x, which="tip")[i, j, ...,drop=FALSE]
+              oldtabnames <- row.names(tdata(x,which="tip"))
+              
+              #### tree handling
+              tip.include <- match(row.names(tab), oldtabnames)
+              tre <- subset(as(x,"phylo4"), tips.include=tip.include)
+
+              ## result
+              res <- phylo4d(x=tre, tip.data=tab)
+              
+              return(res)
+          })
+

Modified: pkg/man/subset-methods.Rd
===================================================================
--- pkg/man/subset-methods.Rd	2008-02-23 13:52:13 UTC (rev 117)
+++ pkg/man/subset-methods.Rd	2008-02-23 15:03:53 UTC (rev 118)
@@ -5,9 +5,22 @@
 \alias{subset,phylo-method}
 \alias{subset,phylo4-method}
 \alias{subset,phylo4d-method}
+\alias{[,phylo4-method}
+\alias{[,phylo4d-method}
 \title{Methods for creating subsets of phylogenies}
 \description{
-  Methods for creating subsets of phylogenies, based on pruning a tree to include or exclude a set of terminal taxa, to include all descendants of the MRCA of two taxa, or eventually to a subtree rooted at a given node.
+  Methods for creating subsets of phylogenies, based on pruning a tree
+  to include or exclude a set of terminal taxa, to include all
+  descendants of the MRCA of two taxa, or eventually to a subtree rooted
+  at a given node.\cr
+
+  The "[" operator can be used with \linkS4class{phylo4} and
+  \linkS4class{phylo4d} objects. With a \linkS4class{phylo4} object
+  'foo', \code{foo[i]} creates a subset of \code{foo} taking \code{i}
+  for a tip index. With a \linkS4class{phylo4d} object
+  'foo', \code{foo[i,j]} creates a subset of \code{foo} taking \code{i}
+  for a tip index and \code{j} for the index of tips variables (see
+  details).\cr 
 }
 \section{Methods}{
   \describe{
@@ -35,24 +48,41 @@
   \item{\dots}{further arguments to be passed to other methods}
 }
 \details{
-  To be described.
-
   The arguments \code{tip} can be either character or numeric. In the
   first case, it gives the labels of the tips to be deleted; in the
   second case the numbers of these labels in the vector
-  \code{phy\$tip.label} are given
+  \code{phy\$tip.label} are given.\cr
+
+  The indices used with the \code{[} operator can be characters, integers
+  or logical, just like with a vector or a matrix.\cr
+  If \code{foo} is a \linkS4class{phylo4d} object, the index of
+  variables ("j") is optional: \code{foo[i,j]} is the same as
+  \code{foo[i]}.\cr
+  
 }
 \value{
   an object of class \code{"phylo4"}
 }
-\author{Steven Kembel \email{skembel at berkeley.edu} and Damien de Vienne \email{damien.de-vienne at u-psud.fr}}
+\author{Steven Kembel \email{skembel at berkeley.edu}\cr
+  Damien de Vienne \email{damien.de-vienne at u-psud.fr}\cr
+  Thibaut Jombart \email{jombart at biomserv.univ-lyon1.fr}
+}
 \examples{
-library(geiger)
 data(geospiza)
-g1 <- as(geospiza$geospiza.tree,"phylo4")
+
+## "subset" examples
+g1 <- as(geospiza,"phylo4")
 plot(subset(g1,tips.exclude="scandens"))
 plot(subset(g1,mrca=c("scandens","fortis","pauper")))
 plot(subset(g1,node.subtree=18))
+
+## "[" examples
+par(mfrow=c(1,2),mar=rep(.1,4))
+plot(g1,show.node=TRUE)
+plot(g1[c(1:6,14)],show.node=TRUE)
+
+plot(geospiza[c(1:6,14)],show.node=TRUE,cex.sym=.5,cex.label=.7)
+plot(geospiza[c(1:6,14),3:5],show.node=TRUE,cex.sym=.5,cex.label=.7)
 }
 \keyword{manip}
 \keyword{methods}

Modified: pkg/tests/plottest.R
===================================================================
--- pkg/tests/plottest.R	2008-02-23 13:52:13 UTC (rev 117)
+++ pkg/tests/plottest.R	2008-02-23 15:03:53 UTC (rev 118)
@@ -27,7 +27,7 @@
 g3 = subset(g2,tips.exclude=c("fuliginosa","fortis","magnirostris",
                  "conirostris","scandens"))
 plot(extract.tree(g3))  ## phylo4
-plot(g3,ratio=.5)
+plot(g3,ratio=.5,cex.sym=.7,cex.lab=.8)
 
 
 ## Playing with new ways of plotting



More information about the Phylobase-commits mailing list