condition_maps: Evaluate conditions signalled in 'future_map' calls

future_cnd_mapR Documentation

Evaluate conditions signalled in future_map calls

Description

These functions let you see the messages, warnings, and errors signalled in future_map calls.

Currently, the only conditions (here meaning: messages, warnings, and errors) that are kept in non-sequential future plans are errors. If you ran some complicated models on remote servers via future_map, and some of these models gave you important warnings, no functions outside of the future_map call would ever 'know' about them.

Similar to the future_walk series of functions, the future_cnd_map functions will collect and preserve these conditions, but instead of converting them to strings and getting rid of the returned values, these functions will keep the conditions as S3 condition objects as well as returning the actual values in "value".

signal_fm_conditions takes the result of these functions, signals all the conditions for each element (displaying them grouped together sequentially for easier reading), and returns the value of the map. evaluate_fm_results does the same thing, but doesn't signal messages and warnings.

Usage

future_cnd_map(.x, .f, ..., .progress = FALSE,
  .options = future_options())

future_cnd_imap(.x, .f, ..., .progress = FALSE,
  .options = future_options())

future_cnd_map2(.x, .y, .f, ..., .progress = FALSE,
  .options = future_options())

future_cnd_pmap(.l, .f, ..., .progress = FALSE,
  .options = future_options())

evaluate_fm_results(future_cnd_map_results, signalErrors = TRUE)

signal_fm_conditions(future_cnd_map_results, displayErrors = TRUE)

Arguments

.x

A list or atomic vector.

.f

A function, formula, or atomic vector.

If a function, it is used as is.

If a formula, e.g. ~ .x + 2, it is converted to a function. There are three ways to refer to the arguments:

  • For a single argument function, use .

  • For a two argument function, use .x and .y

  • For more arguments, use ..1, ..2, ..3 etc

This syntax allows you to create very compact anonymous functions.

If character vector, numeric vector, or list, it is converted to an extractor function. Character vectors index by name and numeric vectors index by position; use a list to index by position and name at different levels. Within a list, wrap strings in get-attr() to extract named attributes. If a component is not present, the value of .default will be returned.

...

Additional arguments passed on to .f.

.progress

A logical, for whether or not to print a progress bar for multiprocess, multisession, and multicore plans.

.options

The future specific options to use with the workers. This must be the result from a call to future_options().

.y

Vectors of the same length. A vector of length 1 will be recycled.

.l

A list of lists. The length of .l determines the number of arguments that .f will be called with. List names will be used if present.

future_cnd_map_results

the output of one of the future_cnd_map-esque functions

signalErrors

whether to signal errors or ignore them. You probably should not ignore errors.

displayErrors

whether to display all the errors that happened in the call before signalling them. Helpful in seeing which elements went wrong.

Details

Like the future_walk series of functions, the future_cnd_map functions can be easily expanded with the future_map_maker function. You simply need to pick the future_map function you want to imitate and add the asStrings = FALSE argument. For example, you could make a future_cnd_map_chr function as easily as: future_cnd_map_chr <- future_map_maker(furrr::future_map_chr, asStrings = FALSE).

See Also

future_map_maker

Examples

future::plan(sequential) # other plans work fine as well
res <- future_cnd_map(1:3, function(i) {
  message(i)
  warning("Uh oh... ", i)
  if (i==2)
    warning("Additional warning!")
  if (i==3)
    stop("OH NO!")
  i + 3
})
## Not run: signal_fm_conditions(res)

burchill/cs documentation built on May 28, 2023, 1:29 p.m.