plapply | R Documentation |
lapply
Verbose and parallelized version of lapply
wrapping around
mclapply
and parLapply
in the base package parallel.
This wrapper can take care of the .Random.seed
and
print progress information (not for cluster-based parallelization).
With the default arguments it equals lapply
enriched by a progress bar.
plapply(X, FUN, ...,
.parallel = 1, .seed = NULL, .verbose = TRUE)
X , FUN , ... |
see |
.parallel |
the number of processes to use in parallel operation, or a
|
.seed |
If set (non- |
.verbose |
if and how progress information should be displayed, i.e., what to
do on each exit of |
a list of the results of calling FUN
on each value of X
.
Sebastian Meyer
mclapply
and parLapply
## example inspired by help("lapply")
x <- list(a = 1:10, beta = exp(-3:3), logic = c(TRUE,FALSE,FALSE,TRUE))
## if neither parallel nor verbose then this simply equals lapply()
plapply(x, quantile, probs = 1:3/4, .verbose = FALSE)
## verbose lapply() -- not really useful for such fast computations
res <- plapply(x, quantile, probs = 1:3/4, .verbose = TRUE)
res <- plapply(x, quantile, probs = 1:3/4, .verbose = "|")
res <- plapply(x, quantile, probs = 1:3/4,
.verbose = quote(cat("length(x) =", length(x), "\n")))
## setting the seed for reproducibility of results involving the RNG
samp <- plapply(as.list(1:3), runif, .seed = 1)
## parallel lapply()
res <- plapply(x, quantile, probs = 1:3/4, .parallel = 2, .verbose = FALSE)
## using a predefined cluster
library("parallel")
cl <- makeCluster(getOption("cl.cores", 2))
res <- plapply(x, quantile, probs = 1:3/4, .parallel = cl)
stopCluster(cl)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.