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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 14 16:36:26 CEST 2011


Author: jarioksa
Date: 2011-09-14 16:36:26 +0200 (Wed, 14 Sep 2011)
New Revision: 1846

Modified:
   pkg/vegan/R/commsimulator.R
   pkg/vegan/R/nesteddisc.R
   pkg/vegan/R/permuted.index.R
   pkg/vegan/R/poolaccum.R
Log:
sample -> sample.int in suitable places (feels faster, but little measurable effect)

Modified: pkg/vegan/R/commsimulator.R
===================================================================
--- pkg/vegan/R/commsimulator.R	2011-09-14 14:35:21 UTC (rev 1845)
+++ pkg/vegan/R/commsimulator.R	2011-09-14 14:36:26 UTC (rev 1846)
@@ -19,17 +19,17 @@
             p <- p*p
         out <- matrix(0, nrow=nr, ncol=nc)
         for (i in 1:nr)
-            out[i,sample(nc, rs[i], prob=p)] <- 1 
+            out[i,sample.int(nc, rs[i], prob=p)] <- 1 
     }
     else if (method == "r00") {
         out <- numeric(nr*nc)
-        out[sample(length(out), sum(x))] <- 1
+        out[sample.int(length(out), sum(x))] <- 1
     }
     else if (method == "c0") {
         cs <- colSums(x)
         out <- matrix(0, nrow=nr, ncol=nc)
         for (j in 1:nc)
-            out[sample(nr, cs[j]), j] <- 1
+            out[sample.int(nr, cs[j]), j] <- 1
     } else if (method == "swap") {
         out <- .C("swap", m = as.integer(x), as.integer(nrow(x)),
                   as.integer(ncol(x)), as.integer(thin),

Modified: pkg/vegan/R/nesteddisc.R
===================================================================
--- pkg/vegan/R/nesteddisc.R	2011-09-14 14:35:21 UTC (rev 1845)
+++ pkg/vegan/R/nesteddisc.R	2011-09-14 14:36:26 UTC (rev 1846)
@@ -42,7 +42,7 @@
                 perm <- matrix(allPerms(le[i]), ncol=le[i]) + cle[i]
                 ## Take at maximum NITER cases from complete enumeration
                 if (nrow(perm) >= NITER) {
-                    perm <- perm[sample(nrow(perm), NITER),]
+                    perm <- perm[sample.int(nrow(perm), NITER),]
                     ties <- TRUE
                 }
             }

Modified: pkg/vegan/R/permuted.index.R
===================================================================
--- pkg/vegan/R/permuted.index.R	2011-09-14 14:35:21 UTC (rev 1845)
+++ pkg/vegan/R/permuted.index.R	2011-09-14 14:36:26 UTC (rev 1846)
@@ -2,7 +2,7 @@
     function (n, strata) 
 {
     if (missing(strata) || is.null(strata)) 
-        out <- sample(n, n)
+        out <- sample.int(n, n)
     else {
         out <- 1:n
         inds <- names(table(strata))

Modified: pkg/vegan/R/poolaccum.R
===================================================================
--- pkg/vegan/R/poolaccum.R	2011-09-14 14:35:21 UTC (rev 1845)
+++ pkg/vegan/R/poolaccum.R	2011-09-14 14:36:26 UTC (rev 1846)
@@ -10,7 +10,7 @@
     ## specpool() is slow, but the vectorized versions below are
     ## pretty fast
     for (i in 1:permutations) {
-        take <- sample(n)
+        take <- sample.int(n, n)
         tmp <- apply(x[take,] > 0, 2, cumsum)
         S[,i] <- rowSums(tmp > 0)
         ## All-zero species are taken as *known* to be missing in



More information about the Vegan-commits mailing list