Learn R Programming

pbmcapply (version 1.1.0)

pbmcmapply: Tracking mcmapply with progress bar

Description

pbmcmapply is a wrapper around the mcmapply function. It adds a progress bar to mcmapply function.

This function works on *nix (Linux, Unix such as macOS) system only due to the lack of fork() functionality, which is essential for mcapply, on Windows.

Usage

pbmcmapply(FUN, ..., MoreArgs = NULL, mc.style = 3, mc.cores =getOption("mc.cores", 2L))

Arguments

FUN
the function to be applied in parallel to ...
...
arguments to vectorize over (vectors or lists of strictly positive length, or all of zero length).
MoreArgs
a list of other arguments to FUN.
mc.cores
see mcmapply.
mc.style
style of the progress bar. See txtProgressBar.

Examples

Run this code
# A lazy sqrt function which doesn't care about efficiency
lazySqrt <- function(num) {
  # Sleep randomly between 0 to 1 second
  Sys.sleep(runif(1))
  return(sqrt(num))
}
# Get the sqrt of 1-5 in parallel
if (length(grep("windows", Sys.info()["sysname"], ignore.case = TRUE))) {
  # Windows Machine does not support mc(*)apply
  result <- pbmclapply(1:5, lazySqrt, mc.cores = 1)
} else {
  # Get the sqrt of 1-5 in parallel
  result <- pbmclapply(1:5, lazySqrt)
}

Run the code above in your browser using DataLab