pbmclapply {pbmcapply} | R Documentation |
Tracking mclapply with progress bar
Description
pbmclapply
is a wrapper around the mclapply
function. It adds a progress bar to mclapply
function.
Parallelization (mc.core > 1) works only on *nix (Linux, Unix such as macOS) system due to the lack of fork()
functionality, which is essential for mcapply, on Windows.
Usage
pbmclapply(X, FUN, ...,
mc.style = "ETA", mc.substyle = NA,
mc.cores = getOption("mc.cores", 2L),
ignore.interactive = getOption("ignore.interactive", F),
mc.preschedule = TRUE, mc.set.seed = TRUE,
mc.cleanup = TRUE, mc.allow.recursive = TRUE)
Arguments
X |
a vector (atomic or list) or an expressions vector. Other objects (including classed objects) will be coerced by |
FUN |
the function to be applied to. |
... |
optional arguments to FUN. |
mc.cores |
see |
mc.style , mc.substyle |
style of the progress bar. See |
ignore.interactive |
whether the |
mc.preschedule , mc.set.seed , mc.cleanup , mc.allow.recursive |
See |
Examples
# A lazy sqrt function which doesn't care about efficiency
lazySqrt <- function(num) {
# Sleep randomly between 0 to 0.5 second
Sys.sleep(runif(1, 0, 0.5))
return(sqrt(num))
}
# On Windows, set cores to be 1
if (.Platform$OS.type == "windows") {
cores = 1
} else {
cores = 2
}
# A lazy and chatty sqrt function.
# An example of passing arguments to pbmclapply.
lazyChattySqrt <- function(num, name) {
# Sleep randomly between 0 to 0.5 second
Sys.sleep(runif(1, 0, 0.5))
return(sprintf("Hello %s, the sqrt of %f is %f.", toString(name), num, sqrt(num)))
}
# Get the sqrt of 1-3 in parallel
result <- pbmclapply(1:3, lazySqrt, mc.cores = cores)
chattyResult <- pbmclapply(1:3, lazyChattySqrt, "Bob", mc.cores = cores)
[Package pbmcapply version 1.5.1 Index]