[Vegan-commits] r1972 - in permbranches/0.6: . R inst

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Oct 31 17:23:35 CET 2011


Author: gsimpson
Date: 2011-10-31 17:23:35 +0100 (Mon, 31 Oct 2011)
New Revision: 1972

Modified:
   permbranches/0.6/DESCRIPTION
   permbranches/0.6/R/shuffle-utils.R
   permbranches/0.6/inst/ChangeLog
Log:
shuffleStrata assumed samples were in contiguous blocks

Modified: permbranches/0.6/DESCRIPTION
===================================================================
--- permbranches/0.6/DESCRIPTION	2011-10-31 16:21:04 UTC (rev 1971)
+++ permbranches/0.6/DESCRIPTION	2011-10-31 16:23:35 UTC (rev 1972)
@@ -1,6 +1,6 @@
 Package: permute
 Title: Functions for generating restricted permutations of data
-Version: 0.6-2
+Version: 0.6-3
 Date: $Date$
 Author: Gavin L. Simpson
 Maintainer: Gavin L. Simpson <gavin.simpson at ucl.ac.uk>

Modified: permbranches/0.6/R/shuffle-utils.R
===================================================================
--- permbranches/0.6/R/shuffle-utils.R	2011-10-31 16:21:04 UTC (rev 1971)
+++ permbranches/0.6/R/shuffle-utils.R	2011-10-31 16:23:35 UTC (rev 1972)
@@ -2,27 +2,27 @@
 `shuffleStrata` <- function(strata, type, mirror = FALSE, start = NULL,
                             flip = NULL, nrow, ncol, start.row = NULL,
                             start.col = NULL) {
-    lev <- length(levels(strata))
+    lev <- length(LEVS <- levels(strata))
     ngr <- length(strata) / lev
-    sp <- split(seq(along = strata), strata)
-    if(type == "free") {
-        unname(do.call(c, sp[shuffleFree(lev, lev)]))
-    } else if(type == "series") {
-        unname(do.call(c,
-                       sp[shuffleSeries(seq_len(lev),
-                                        mirror = mirror,
-                                        start = start,
-                                        flip = flip)]))
-    } else if(type == "grid") {
-        unname(do.call(c,
-                       sp[shuffleGrid(nrow = nrow, ncol = ncol,
-                                      mirror = mirror,
-                                      start.row = start.row,
-                                      start.col = start.col,
-                                      flip = flip)]))
+    SEQ <- seq_len(lev)
+    sp <- split(out <- seq_along(strata), strata)
+    perm <- if(type == "free") {
+        shuffleFree(lev, lev)
+    } else if (type == "series") {
+        shuffleSeries(SEQ, mirror = mirror, start = start,
+                      flip = flip)
+    } else if (type == "grid") {
+        shuffleGrid(nrow = nrow, ncol = ncol, mirror = mirror,
+                    start.row = start.row, start.col = start.col,
+                    flip = flip)
     } else {
         stop("Invalid permutation type.")
     }
+    for(i in SEQ) {
+        want <- which(strata == LEVS[i])
+        out[want] <- sp[[perm[i]]]
+    }
+    out
 }
 
 `shuffleGrid` <- function(nrow, ncol, mirror = FALSE, start.row = NULL,

Modified: permbranches/0.6/inst/ChangeLog
===================================================================
--- permbranches/0.6/inst/ChangeLog	2011-10-31 16:21:04 UTC (rev 1971)
+++ permbranches/0.6/inst/ChangeLog	2011-10-31 16:23:35 UTC (rev 1972)
@@ -15,6 +15,9 @@
 	* shuffleGrid: was doing random flipping of permutations even
 	if `mirror = FALSE` for the `constant = TRUE` case.
 
+	* shuffleStrata: assumed that the samples were in contiguous
+	blocks. Reporter by Cajo ter Braak
+
 Version 0.6-1 (released to CRAN on September 7, 2011)
 
 	* NAMESPACE: export(permuplot)



More information about the Vegan-commits mailing list