[Vegan-commits] r966 - in pkg/vegan: R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Aug 31 17:36:49 CEST 2009


Author: jarioksa
Date: 2009-08-31 17:36:49 +0200 (Mon, 31 Aug 2009)
New Revision: 966

Modified:
   pkg/vegan/R/ordiParseFormula.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/vegan-internal.Rd
Log:
infrastructure for NA handling in cca, rda & capscale

Modified: pkg/vegan/R/ordiParseFormula.R
===================================================================
--- pkg/vegan/R/ordiParseFormula.R	2009-08-31 10:32:33 UTC (rev 965)
+++ pkg/vegan/R/ordiParseFormula.R	2009-08-31 15:36:49 UTC (rev 966)
@@ -1,5 +1,5 @@
 "ordiParseFormula" <-
-function (formula, data, xlev = NULL, envdepth = 2) 
+function (formula, data, xlev = NULL, envdepth = 2, na.action = na.fail) 
 {
     Terms <- terms(formula, "Condition", data = data)
     flapart <- fla <- formula <- formula(Terms, width.cutoff = 500)
@@ -8,13 +8,20 @@
     X <- as.matrix(X)
     indPartial <- attr(Terms, "specials")$Condition
     mf <- Z <- NULL
+    ## Get na.action attribute
+    formula[[2]] <- NULL
+    mf <- get_all_vars(formula, data)
+    if (NCOL(mf) > 0)
+        nas <- attr(model.frame(mf, na.action = na.action), "na.action")
+    else
+        nas <- NULL
     if (!is.null(indPartial)) {
         partterm <- attr(Terms, "variables")[1 + indPartial]
         Pterm <- sapply(partterm, function(x) deparse(x[[2]], width.cutoff=500))
         Pterm <- paste(Pterm, collapse = "+")
         P.formula <- as.formula(paste("~", Pterm), env = environment(formula))
         zlev <- xlev[names(xlev) %in% Pterm]
-        mf <- model.frame(P.formula, data, na.action = na.fail, 
+        mf <- model.frame(P.formula, data, na.action = na.pass, 
             xlev = zlev)
         Z <- model.matrix(P.formula, mf)
         if (any(colnames(Z) == "(Intercept)")) {
@@ -22,17 +29,16 @@
             Z <- Z[, -xint, drop = FALSE]
         }
         partterm <- sapply(partterm, function(x) deparse(x, width.cutoff=500))
-        formula <- update(formula, paste(".~.-", paste(partterm, 
+        formula <- update(formula, paste("~.-", paste(partterm, 
             collapse = "-")))
-        flapart <- update(formula, paste(". ~ . +", Pterm))
+        flapart <- update(formula, paste(" ~ . +", Pterm))
     }
-    formula[[2]] <- NULL
     if (formula[[2]] == "1" || formula[[2]] == "0") 
         Y <- NULL
     else {
         if (exists("Pterm")) 
             xlev <- xlev[!(names(xlev) %in% Pterm)]
-        mf <- model.frame(formula, data, na.action = na.fail, 
+        mf <- model.frame(formula, data, na.action = na.pass, 
             xlev = xlev)
         Y <- model.matrix(formula, mf)
         if (any(colnames(Y) == "(Intercept)")) {
@@ -40,6 +46,16 @@
             Y <- Y[, -xint, drop = FALSE]
         }
     }
+    ## Check and remove NA
+    if (!is.null(nas)) {
+        X <- X[-nas,, drop=FALSE]
+        if (!is.null(Y)) {
+            Y <- Y[-nas,, drop=FALSE]
+            mf <- mf[-nas,, drop=FALSE]
+        }
+        if (!is.null(Z))
+            Z <- Z[-nas,, drop=FALSE]
+    }
     rownames(X) <- rownames(X, do.NULL = FALSE)
     colnames(X) <- colnames(X, do.NULL = FALSE)
     if (!is.null(Y)) {
@@ -51,5 +67,6 @@
         colnames(Z) <- colnames(Z, do.NULL = FALSE)
     }
     list(X = X, Y = Y, Z = Z, terms = terms(fla, width.cutoff = 500), 
-        terms.expand = terms(flapart, width.cutoff = 500), modelframe = mf)
+        terms.expand = terms(flapart, width.cutoff = 500), modelframe = mf,
+         na.action = nas)
 }

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2009-08-31 10:32:33 UTC (rev 965)
+++ pkg/vegan/inst/ChangeLog	2009-08-31 15:36:49 UTC (rev 966)
@@ -8,6 +8,10 @@
 	ripley.subs() and ripley.subsets() from vegan. The result should
 	be unchanged.
 
+	* ordiParseFormula: handles missing values with na.action. The
+	calling functions (cca, rda, capscale) won't use this
+	yet (working...).
+
 Version 1.16-25 (closed August 31, 2009)
 
 	* mantel.correlog: updated to the version 1.4 of Pierre Legendre's

Modified: pkg/vegan/man/vegan-internal.Rd
===================================================================
--- pkg/vegan/man/vegan-internal.Rd	2009-08-31 10:32:33 UTC (rev 965)
+++ pkg/vegan/man/vegan-internal.Rd	2009-08-31 15:36:49 UTC (rev 966)
@@ -15,7 +15,7 @@
 }
 \usage{
 ordiGetData(call, env)
-ordiParseFormula(formula, data, xlev = NULL, envdepth = 2)
+ordiParseFormula(formula, data, xlev = NULL, envdepth = 2, na.action = na.fail)
 ordiTerminfo(d, data)
 ordiArrowMul(x, at = c(0,0), fill = 0.75)
 ordiArgAbsorber(..., shrink, origin, scaling, triangular,
@@ -37,7 +37,7 @@
   conditions, possibly \code{NULL}) needed in constrained
   ordination. Argument \code{xlev} is passed to
   \code{\link{model.frame}} and argument \code{envdepth} specifies the
-  depth at which the community data (dependent data) is evaluated;
+  depth at which the community data (dependent data) are evaluated;
   default \code{envdepth = 2} evaluates that in the environment of the
   parent of the calling function, and \code{envdepth = 1} within the
   calling function (see \code{\link{eval.parent}}). \code{ordiTermInfo}



More information about the Vegan-commits mailing list