progressr: Map-Reduce Calls, e.g. lapply() and map()
Henrik Bengtsson
Source:vignettes/progressr-21-map-reduce.md
progressr-21-map-reduce.Rmd
Progress updates by progressr is
designed to work out of the box for any iterator framework in R,
e.g. lapply()
, foreach,
purrr, and
plyr. Below
you will a set of examples that illustrate how to use
progressr in common use cases.
The plyr package
library(plyr)
library(progressr)
handlers(global = TRUE)
my_fcn <- function(xs) {
p <- progressor(along = xs)
llply(xs, function(x, ...) {
Sys.sleep(0.1)
p(sprintf("x=%g", x))
sqrt(x)
})
}
y <- my_fcn(1:10)
# |==================== | 40%
Note how this solution does not make use of plyr’s
.progress
argument, because the above solution is more
powerful and more flexible, e.g. we have more control on progress
updates and their messages. However, if you prefer the traditional
plyr approach, you can use
.progress = "progressr"
,
e.g. y <- llply(..., .progress = "progressr")
.