[Ecopd-commits] r71 - in branches/single-tree: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Nov 17 05:18:08 CET 2009
Author: regetz
Date: 2009-11-17 05:18:08 +0100 (Tue, 17 Nov 2009)
New Revision: 71
Modified:
branches/single-tree/R/utilities.R
branches/single-tree/man/genera.Rd
Log:
modified genera to work on phylo4com objects; updated documentation
Modified: branches/single-tree/R/utilities.R
===================================================================
--- branches/single-tree/R/utilities.R 2009-11-17 04:08:48 UTC (rev 70)
+++ branches/single-tree/R/utilities.R 2009-11-17 04:18:08 UTC (rev 71)
@@ -110,10 +110,23 @@
return(phy)
}
+##TODO method-ize this, adding method for phylo4, then calling that
+##method from this more complex phylo4com method
# genera extractor
-genera <- function(phy) {
- #From taxa names in tree, remove "_" and species name after
- gsub("_.*$", "", tipLabels(phy))
+genera <- function(phy, comm) {
+ if (missing(comm)) {
+ comm <- communities(phy)
+ }
+ doNotExist <- !comm %in% communities(phy)
+ if (any(doNotExist)) {
+ stop("one or more communities not found in phy: ",
+ paste(comm[doNotExist], collapse=", "))
+ }
+ # From taxa names in tree, remove "_" and species name after
+ g <- lapply(phy at subtrees[phy at metadata$comms[comm]], function(x)
+ gsub("_.*$", "", tipLabels(x)))
+ names(g) <- comm
+ return(g)
}
# community labels extractor
Modified: branches/single-tree/man/genera.Rd
===================================================================
--- branches/single-tree/man/genera.Rd 2009-11-17 04:08:48 UTC (rev 70)
+++ branches/single-tree/man/genera.Rd 2009-11-17 04:18:08 UTC (rev 71)
@@ -7,10 +7,11 @@
nomenclature.
}
\usage{
- genera(phy)
+ genera(phy, comm)
}
\arguments{
- \item{phy}{a \code{phylo4} object (or one that inherits from it)}
+ \item{phy}{a \code{phylo4com} object}
+ \item{comm}{a vector of community labels; if missing, all communities}
}
\details{
This is a simple function that assumes the tip labels of phylogeny
@@ -18,11 +19,13 @@
whatsoever to check whether this is in fact the case.
}
\value{
- A character vector containing the genus portion of the tip labels,
- with element names corresponding to the numeric tip node ID.
+ A list of character vectors, one per community, containing the genus
+ portion of the tip labels, with element names corresponding to the
+ numeric tip node ID.
}
\author{Jim Regetz (regetz at nceas.ucsb.edu)}
\examples{
data(weeds)
- genera(weeds$A)
+ genera(weeds, "A")
+ genera(weeds)
}
More information about the Ecopd-commits
mailing list