pbmcmapply: Tracking mcmapply with progress bar

Description Usage Arguments Examples

View source: R/pbmcmapply.R

Description

pbmcmapply is a wrapper around the mcmapply function. It adds a progress bar to mcmapply 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

1
2
3
4
pbmcmapply(FUN, ..., MoreArgs = NULL,
           mc.style = "ETA", mc.substyle = NA,
           mc.cores =getOption("mc.cores", 2L),
           ignore.interactive = getOption("ignore.interactive", F))

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, mc.substyle

style of the progress bar. See progressBar.

ignore.interactive

whether the interactive() is ignored. If set to TRUE, the progress bar will be printed even in a non-interactive environment (e.g. called by Rscript). Can be set as an option "ignore.interactive".

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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 pbmcmapply.
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 <- pbmcmapply(lazySqrt, 1:3, mc.cores = cores)
chattyResult <- pbmcmapply(lazyChattySqrt, 1:3, MoreArgs = list("Bob"), mc.cores = cores)

pbmcapply documentation built on May 31, 2017, 5:20 a.m.

Search within the pbmcapply package
Search all R packages, documentation and source code