[Vegan-commits] r1755 - in pkg/vegan: R inst
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Aug 24 13:50:11 CEST 2011
Author: jarioksa
Date: 2011-08-24 13:50:11 +0200 (Wed, 24 Aug 2011)
New Revision: 1755
Modified:
pkg/vegan/R/specpool.R
pkg/vegan/inst/ChangeLog
pkg/vegan/inst/NEWS.Rd
Log:
specpool works with NA values in 'pool', empty factor levels and checks input
Modified: pkg/vegan/R/specpool.R
===================================================================
--- pkg/vegan/R/specpool.R 2011-08-24 10:30:54 UTC (rev 1754)
+++ pkg/vegan/R/specpool.R 2011-08-24 11:50:11 UTC (rev 1755)
@@ -4,6 +4,14 @@
x <- as.matrix(x)
if (missing(pool))
pool <- rep("All", nrow(x))
+ ## check dims
+ if (length(pool) != NROW(x))
+ stop("length of 'pool' and number rows in 'x' do not match")
+ ## remove missing values
+ if (any(nas <- is.na(pool))) {
+ pool <- pool[!nas]
+ x <- x[!nas, , drop = FALSE]
+ }
out <- seq(1:nrow(x))
groups <- table(pool)
inds <- names(groups)
@@ -15,6 +23,8 @@
a1 <- a2 <- NA
gr <- out[pool == is]
n <- length(gr)
+ if (n <= 0)
+ next
X <- x[gr, , drop = FALSE]
freq <- colSums(X > 0)
p <- freq[freq > 0]/n
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2011-08-24 10:30:54 UTC (rev 1754)
+++ pkg/vegan/inst/ChangeLog 2011-08-24 11:50:11 UTC (rev 1755)
@@ -12,6 +12,9 @@
each fitted model. Function fitspecaccum() is written so that
default fitted(), residuals() and coef() work.
+ * specpool: failed if 'pool' had NA values or empty factor
+ levels. Checks that 'pool' length matches nrow of data.
+
* NAMESPACE: imports nobs from permute_0.5-3 in R 2.12.2 and older
which do not yet have nobs() generic.
Modified: pkg/vegan/inst/NEWS.Rd
===================================================================
--- pkg/vegan/inst/NEWS.Rd 2011-08-24 10:30:54 UTC (rev 1754)
+++ pkg/vegan/inst/NEWS.Rd 2011-08-24 11:50:11 UTC (rev 1755)
@@ -86,7 +86,12 @@
\subsection{BUG FIXES}{
\itemize{
- \item None yet.
+
+ \item \code{specpool} failed if the grouping factor \code{pool}
+ had missing values or empty factor levels. Now also checks that
+ the length of the \code{pool} matches the number of
+ observations.
+
}
} % end BUG FIXES
More information about the Vegan-commits
mailing list