mcMap: mclapply with error and warning handlers

Description Usage Arguments Details Value Examples

View source: R/mcMap.R

Description

This is a wrapper around parallel::mclapply. It supports different options for handling errors and warnings on nodes.

Usage

1
2
3
mcMap(x, f, ..., errors = getErrorsOption(),
  warnings = getWarningsOption(),
  warningsWhitelist = getWarningsWhitelist(), finallyStop = FALSE)

Arguments

x

(vector) a vector to iterate over

f

(function)

...

arguments passed to mclapply

errors

(character) one in c("suppress", "log")

warnings

(character) one in c("suppress", "log", "asError")

warningsWhitelist

(character) a vector of regular expressions for white-listing warnings.

finallyStop

(logical) if we want to raise an error if any of the nodes produced one.

Details

This implementation has the same limitations as mclapply: GUIs (like RStudio) do not handle console output well. As the documentation of mclapply already states: this function is not designed for interactive sessions.

The arguments errors and warnings control how errors and warnings are dealt with. When warnings = "asError" is specified, warnings are escalated into errors unless they are on the whitelist, which, by default, is empty.

Value

Unlike mclapply not an object of class 'try-error' is returned, but a simpleError in case of errors. This is also the case when warnings are errors.

Examples

1
mcMap(1:2, function(x) if (x == 2) stop("Don't like '2'!") else x)

INWT/mctools documentation built on Sept. 24, 2021, 9:19 p.m.