[Dplr-commits] r684 - branches/redfit/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 4 14:08:26 CEST 2013


Author: mvkorpel
Date: 2013-09-04 14:08:26 +0200 (Wed, 04 Sep 2013)
New Revision: 684

Modified:
   branches/redfit/R/detrend.R
   branches/redfit/R/rwi.stats.running.R
Log:
Functions (operators) from Suggested packages "foreach" and
"iterators" are called using the `::` operator.  The packages are
loaded with requireNamespace() instead of require().
Consequences:
* no names from "foreach" or "iterators" will be added to the user's workspace
* eliminates possibility of name space conflicts
* avoids nag from codetools::checkUsagePackage("dplR")


Modified: branches/redfit/R/detrend.R
===================================================================
--- branches/redfit/R/detrend.R	2013-09-04 10:09:48 UTC (rev 683)
+++ branches/redfit/R/detrend.R	2013-09-04 12:08:26 UTC (rev 684)
@@ -14,24 +14,29 @@
     if(!make.plot &&
        ("Spline" %in% method2 || "ModNegExp" %in% method2) &&
        !inherits(try(suppressWarnings(req.it <-
-                                      require(iterators, quietly=TRUE)),
+                                      requireNamespace("iterators",
+                                                       quietly=TRUE)),
                      silent = TRUE),
                  "try-error") && req.it &&
        !inherits(try(suppressWarnings(req.fe <-
-                                      require(foreach, quietly=TRUE)),
+                                      requireNamespace("foreach",
+                                                       quietly=TRUE)),
                      silent = TRUE),
                  "try-error") && req.fe){
-        it.rwl <- iter(rwl, by = "col")
+        it.rwl <- iterators::iter(rwl, by = "col")
         ## a way to get rid of "no visible binding" NOTE in R CMD check
         rwl.i <- NULL
-        out <- foreach(rwl.i=it.rwl, .packages="dplR") %dopar% {
-            fits <- detrend.series(rwl.i, make.plot=FALSE,
-                                   method=method2, nyrs=nyrs, f=f,
-                                   pos.slope=pos.slope)
-            if(is.data.frame(fits))
-                row.names(fits) <- rn
-            fits
-        }
+        out <- foreach::"%dopar%"(foreach::foreach(rwl.i=it.rwl,
+                                                   .packages="dplR"),
+                              {
+                                  fits <- detrend.series(rwl.i, make.plot=FALSE,
+                                                         method=method2,
+                                                         nyrs=nyrs, f=f,
+                                                         pos.slope=pos.slope)
+                                  if(is.data.frame(fits))
+                                      row.names(fits) <- rn
+                                  fits
+                              })
     } else{
         out <- list()
         for(i in seq_len(ncol(rwl))){

Modified: branches/redfit/R/rwi.stats.running.R
===================================================================
--- branches/redfit/R/rwi.stats.running.R	2013-09-04 10:09:48 UTC (rev 683)
+++ branches/redfit/R/rwi.stats.running.R	2013-09-04 12:08:26 UTC (rev 684)
@@ -328,14 +328,15 @@
     ## Iterate over all windows
     if (running.window &&
         !inherits(try(suppressWarnings(req.fe <-
-                                       require(foreach, quietly=TRUE)),
+                                       requireNamespace("foreach",
+                                                        quietly=TRUE)),
                       silent = TRUE),
                   "try-error") && req.fe) {
         compos.stats <-
-            foreach(s.idx=window.start, .combine="rbind",
-                    .packages="dplR") %dopar% {
-                        loop.body(s.idx)
-                    }
+            foreach::"%dopar%"(foreach::foreach(s.idx=window.start,
+                                                .combine="rbind",
+                                                .packages="dplR"),
+                               loop.body(s.idx))
     } else {
         compos.stats <- NULL
         for (s.idx in window.start) {



More information about the Dplr-commits mailing list