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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 4 12:24:00 CET 2015


Author: jarioksa
Date: 2015-03-04 12:24:00 +0100 (Wed, 04 Mar 2015)
New Revision: 2935

Modified:
   pkg/vegan/R/capscale.R
   pkg/vegan/R/ordiGetData.R
   pkg/vegan/R/ordiParseFormula.R
   pkg/vegan/man/vegan-internal.Rd
Log:
Merge branch 'cran-2.2' into r-forge-svn-local

Modified: pkg/vegan/R/capscale.R
===================================================================
--- pkg/vegan/R/capscale.R	2015-03-04 11:14:29 UTC (rev 2934)
+++ pkg/vegan/R/capscale.R	2015-03-04 11:24:00 UTC (rev 2935)
@@ -16,8 +16,8 @@
     ## The following line was eval'ed in environment(formula), but
     ## that made update() fail. Rethink the line if capscale() fails
     ## mysteriously at this point.
-    X <- eval(formula[[2]], envir=parent.frame(),
-              enclos = environment(formula))
+    X <- eval(formula[[2]], envir=environment(formula),
+              enclos = globalenv())
     if (!inherits(X, "dist")) {
         comm <- X
         dfun <- match.fun(dfun)
@@ -45,22 +45,22 @@
     ## evaluate formula: ordiParseFormula will return dissimilarities
     ## as a symmetric square matrix (except that some rows may be
     ## deleted due to missing values)
-    fla <- update(formula, X ~ .)
-    environment(fla) <- environment()
-    d <- ordiParseFormula(fla,
-                          if(is.data.frame(data) && !is.null(comm)) cbind(data, comm)
-                          else data,
-                          envdepth = 1, na.action = na.action,
+    d <- ordiParseFormula(formula,
+                          data,
+                          na.action = na.action,
                           subset = substitute(subset))
     ## ordiParseFormula subsets rows of dissimilarities: do the same
-    ## for columns ('comm' is handled later)
-    if (!is.null(d$subset))
-        d$X <- d$X[, d$subset, drop = FALSE]
+    ## for columns ('comm' is handled later). ordiParseFormula
+    ## returned the original data, but we use instead the potentially
+    ## changed X and discard d$X.
+    if (!is.null(d$subset)) {
+        X <- as.matrix(X)[d$subset, d$subset, drop = FALSE]
+    }
     ## Delete columns if rows were deleted due to missing values
     if (!is.null(d$na.action)) {
-        d$X <- d$X[, -d$na.action, drop = FALSE]
+        X <- as.matrix(X)[-d$na.action, -d$na.action, drop = FALSE]
     }
-    X <- as.dist(d$X)
+    X <- as.dist(X)
     k <- attr(X, "Size") - 1
     if (sqrt.dist)
         X <- sqrt(X)

Modified: pkg/vegan/R/ordiGetData.R
===================================================================
--- pkg/vegan/R/ordiGetData.R	2015-03-04 11:14:29 UTC (rev 2934)
+++ pkg/vegan/R/ordiGetData.R	2015-03-04 11:24:00 UTC (rev 2935)
@@ -6,5 +6,5 @@
     call$na.action <- na.pass
     call[[2]] <- NULL
     call[[1]] <- as.name("model.frame")
-    eval(call, env)
+    eval(call, env, enclos = .GlobalEnv)
 }

Modified: pkg/vegan/R/ordiParseFormula.R
===================================================================
--- pkg/vegan/R/ordiParseFormula.R	2015-03-04 11:14:29 UTC (rev 2934)
+++ pkg/vegan/R/ordiParseFormula.R	2015-03-04 11:24:00 UTC (rev 2935)
@@ -1,5 +1,5 @@
-"ordiParseFormula" <-
-function (formula, data, xlev = NULL, envdepth = 2, na.action = na.fail,
+`ordiParseFormula` <-
+function (formula, data, xlev = NULL, na.action = na.fail,
           subset = NULL) 
 {
     if (missing(data))
@@ -7,7 +7,7 @@
     Terms <- terms(formula, "Condition", data = data)
     flapart <- fla <- formula <- formula(Terms, width.cutoff = 500)
     specdata <- formula[[2]]
-    X <- eval.parent(specdata, n = envdepth)
+    X <- eval(specdata, environment(formula), enclos=globalenv())
     ## X is usually a matrix, but it is "dist" with capscale():
     X <- as.matrix(X)
     indPartial <- attr(Terms, "specials")$Condition
@@ -19,8 +19,12 @@
         Pterm <- paste(Pterm, collapse = "+")
         P.formula <- as.formula(paste("~", Pterm), env = environment(formula))
         zlev <- xlev[names(xlev) %in% Pterm]
-        zmf <- model.frame(P.formula, data, na.action = na.pass, 
-            xlev = zlev)
+        zmf <- if (inherits(data, "environment"))
+            eval(substitute(
+                model.frame(P.formula, na.action = na.pass, xlev = zlev)),
+                 envir = data, enclos = .GlobalEnv)
+        else
+            model.frame(P.formula, data, na.action = na.pass, xlev = zlev)
         partterm <- sapply(partterm, function(x) deparse(x, width.cutoff=500))
         formula <- update(formula, paste("~.-", paste(partterm, 
             collapse = "-")))
@@ -31,8 +35,13 @@
     else {
         if (exists("Pterm")) 
             xlev <- xlev[!(names(xlev) %in% Pterm)]
-        ymf <- model.frame(formula, data, na.action = na.pass, 
-            xlev = xlev)
+
+        ymf <- if (inherits(data, "environment"))
+            eval(substitute(
+                model.frame(formula, na.action = na.pass, xlev = xlev)),
+                 envir=data, enclos=.GlobalEnv)
+        else
+            model.frame(formula, data, na.action = na.pass, xlev = xlev) 
     }
     ## Combine condition an constrain data frames
     if (!is.null(zmf)) {

Modified: pkg/vegan/man/vegan-internal.Rd
===================================================================
--- pkg/vegan/man/vegan-internal.Rd	2015-03-04 11:14:29 UTC (rev 2934)
+++ pkg/vegan/man/vegan-internal.Rd	2015-03-04 11:24:00 UTC (rev 2935)
@@ -23,8 +23,8 @@
 }
 \usage{
 ordiGetData(call, env)
-ordiParseFormula(formula, data, xlev = NULL, envdepth = 2, 
-   na.action = na.fail, subset = NULL)
+ordiParseFormula(formula, data, xlev = NULL,  na.action = na.fail,
+    subset = NULL)
 ordiTerminfo(d, data)
 ordiNAexclude(x, excluded)
 ordiNApredict(omit, x)
@@ -54,18 +54,13 @@
   matrices (dependent variables, and \code{\link{model.matrix}} of
   constraints and 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) 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} finds the term
+  \code{\link{model.frame}}. \code{ordiTermInfo} finds the term
   information for constrained ordination as described in
   \code{\link{cca.object}}. \code{ordiNAexclude} implements
   \code{na.action = na.exclude} for constrained ordination finding WA
   scores of CCA components and site scores of unconstrained component
   from \code{excluded} rows of observations. Function
-  \code{ordiNApredict} puts pads the result object with these or with
+  \code{ordiNApredict} pads the result object with these or with
   WA scores similarly as \code{\link{napredict}}.
 
   \code{ordiArrowMul} finds a multiplier to scale a bunch of arrows to



More information about the Vegan-commits mailing list