surveillance (version 1.12.1)

plapply: Verbose and Parallel lapply

Description

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.

Usage

plapply(X, FUN, ...,
        .parallel = 1, .seed = NULL, .verbose = TRUE)

Arguments

X,FUN,...
see lapply.
.parallel
the number of processes to use in parallel operation, or a "cluster" object (see makeCluster). If a number, mclapply
.seed
If set (non-NULL), results involving random number generation become reproducible. If using a cluster (see the .parallel argument), clusterSetRNGStream
.verbose
if and how progress information should be displayed, i.e., what to do on each exit of FUN. This is unsupported and ignored for cluster-based parallelization and primitive FUNctions. The default (TRUE) wil

Value

  • a list of the results of calling FUN on each value of X.

See Also

mclapply and parLapply

Examples

Run this code
## 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), "")))

## 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)

## using a predefined cluster
library("parallel")
cl <- makeCluster(getOption("cl.cores", 2))
res <- plapply(x, quantile, probs = 1:3/4, .parallel = cl)
stopCluster(cl)

Run the code above in your browser using DataLab