[Vegan-commits] r2748 - pkg/vegan/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Nov 24 08:38:27 CET 2013


Author: jarioksa
Date: 2013-11-24 08:38:26 +0100 (Sun, 24 Nov 2013)
New Revision: 2748

Modified:
   pkg/vegan/R/anovacca.R
   pkg/vegan/R/permutest.cca.R
Log:
take Random.seed and control from permutationMatrix

Modified: pkg/vegan/R/anovacca.R
===================================================================
--- pkg/vegan/R/anovacca.R	2013-11-23 08:05:04 UTC (rev 2747)
+++ pkg/vegan/R/anovacca.R	2013-11-24 07:38:26 UTC (rev 2748)
@@ -4,10 +4,6 @@
              parallel = getOption("mc.cores"), strata = NULL) 
 {
     model <- match.arg(model)
-    if (!exists(".Random.seed", envir = .GlobalEnv,
-                inherits = FALSE)) 
-        runif(1)
-    seed <- get(".Random.seed", envir = .GlobalEnv, inherits = FALSE)
     ## permutations is either a single number, a how() structure or a
     ## permutation matrix
     if (length(permutations) == 1) {
@@ -23,11 +19,14 @@
     }
     ## now permutations is either a how() structure or a permutation
     ## matrix. Make it to a matrix if it is "how"
-    if (inherits(permutations, "how"))
+    if (inherits(permutations, "how")) {
         permutations <- shuffleSet(nrow(object$CA$u),
                                    control = permutations)
-    else # we got a permutation matrix and seed is unknown
-        seed <- NA
+        seed <- attr(permutations, "seed")
+        control <- attr(permutations, "control")
+    }
+    else # we got a permutation matrix and seed & control are unknown
+        seed <- control <- NULL
     nperm <- nrow(permutations)
     ## stop permutations block
     ## see if this was a list of ordination objects
@@ -44,6 +43,8 @@
                               permutations = permutations,
                               model = model,
                               parallel = parallel)
+            attr(sol, "Random.seed") <- seed
+            attr(sol, "control") <- control
             return(sol)
         }
     }
@@ -60,6 +61,8 @@
                       "axis" = anovacca.byaxis(object,
                       permutations = permutations,
                       model = model, parallel = parallel))
+        attr(sol, "Random.seed") <- seed
+        attr(sol, "control") <- control
         return(sol)
     }
     ## basic overall test
@@ -78,6 +81,7 @@
         head <- paste(head, "Permutations stratified within '", 
                       tst$strata, "'\n", sep = "")
     mod <- paste("Model:", c(object$call))
-    structure(table, heading = c(head, mod), Random.seed = seed, 
+    structure(table, heading = c(head, mod), Random.seed = seed,
+              control = control,
               class = c("anova.cca", "anova", "data.frame"))
 }

Modified: pkg/vegan/R/permutest.cca.R
===================================================================
--- pkg/vegan/R/permutest.cca.R	2013-11-23 08:05:04 UTC (rev 2747)
+++ pkg/vegan/R/permutest.cca.R	2013-11-24 07:38:26 UTC (rev 2748)
@@ -111,9 +111,6 @@
         if (isPartial)
             Zcol <- ncol(Z)
     }
-    if (!exists(".Random.seed", envir = .GlobalEnv, inherits = FALSE))
-        runif(1)
-    seed <- get(".Random.seed", envir = .GlobalEnv, inherits = FALSE)
     ## permutations is either a single number, a how() structure or a
     ## permutation matrix
     if (length(permutations) == 1) {
@@ -167,7 +164,9 @@
     sol <- list(call = Call, testcall = x$call, model = model,
                 F.0 = F.0, F.perm = F.perm,  chi = c(Chi.z, Chi.xz),
                 num = num, den = den, df = c(q, r), nperm = nperm,
-                method = x$method, first = first,  Random.seed = seed)
+                method = x$method, first = first)
+    sol$Random.seed <- attr(permutations, "seed")
+    sol$control <- attr(permutations, "control")
     if (!missing(strata)) {
         sol$strata <- deparse(substitute(strata))
         sol$stratum.values <- strata



More information about the Vegan-commits mailing list