[Ecopd-commits] r87 - in branches/single-tree: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Nov 18 20:44:06 CET 2009


Author: regetz
Date: 2009-11-18 20:44:06 +0100 (Wed, 18 Nov 2009)
New Revision: 87

Modified:
   branches/single-tree/R/community.R
   branches/single-tree/R/utilities.R
   branches/single-tree/man/richness.Rd
Log:
fixed richness and moved it from community.R to utilities.R; updated doc


Modified: branches/single-tree/R/community.R
===================================================================
--- branches/single-tree/R/community.R	2009-11-18 19:26:09 UTC (rev 86)
+++ branches/single-tree/R/community.R	2009-11-18 19:44:06 UTC (rev 87)
@@ -21,8 +21,3 @@
   return(mat)
 
 }
-
-# Calculate species richness
-richness <- function(phylo4com, na.rm=FALSE) {
-  sapply(phylo4com, function(x) sum(abundance(x)>0, na.rm=na.rm))
-}

Modified: branches/single-tree/R/utilities.R
===================================================================
--- branches/single-tree/R/utilities.R	2009-11-18 19:26:09 UTC (rev 86)
+++ branches/single-tree/R/utilities.R	2009-11-18 19:44:06 UTC (rev 87)
@@ -89,6 +89,11 @@
     N
 }
 
+richness <- function(phy, comm, na.zero=FALSE) {
+    P <- presence(phy, comm, na.zero=na.zero)
+    colSums(P)
+}
+
 # minTL extractor
 minTL <- function(phy) {
   minTL <- tipData(phy)$minTL

Modified: branches/single-tree/man/richness.Rd
===================================================================
--- branches/single-tree/man/richness.Rd	2009-11-18 19:26:09 UTC (rev 86)
+++ branches/single-tree/man/richness.Rd	2009-11-18 19:44:06 UTC (rev 87)
@@ -6,26 +6,32 @@
   taxa having positive abundance.
 }
 \usage{
-  richness(phylo4com, na.rm = FALSE)
+  richness(phy, comm, na.zero = FALSE)
 }
 \arguments{
-  \item{phylo4com}{A list of phylo4d objects with abundance data}
-  \item{na.rm}{(logical) Should missing abundance values be treated as
-    absences?}
+  \item{phy}{a \code{phylo4com} object}
+  \item{comm}{a vector of community labels; if missing, all communities}
+  \item{na.zero}{logical. should NAs be treated as zero abundances?}
 }
 \details{
   For each community tree, the upper bound on richness is simply the
   number of tips in the tree. However, the richness value will be lower
-  if any species do not have positive abundance. When \code{na.rm=TRUE},
-  species with \code{NA} abundance are considered missing, otherwise
-  \code{NA} will propagate through to the result.
+  if any species do not have positive abundance. When
+  \code{na.zero=TRUE}, species with \code{NA} abundance are considered
+  missing, otherwise \code{NA} will propagate through to the result.
 }
 \value{
-  Vector of richness values, with names corresponding the community
-  names in the phylo4com list (if they exist).
+  Vector of richness values, with names corresponding to community
+  names in the phylo4com object.
 }
 \author{Jim Regetz (regetz at nceas.ucsb.edu)}
 \examples{
   data(weeds)
   richness(weeds)
+
+  abundance(weeds, "A", 4) <- 0
+  richness(weeds)
+
+  abundance(weeds, "B", 2:3) <- NA
+  richness(weeds, na.zero=TRUE)
 }



More information about the Ecopd-commits mailing list