Learn R Programming

chronicler (version 0.2.2)

purely: Capture all errors, warnings and messages.

Description

Capture all errors, warnings and messages.

Usage

purely(.f, strict = 2)

Value

A function which returns a list. The first element of the list, `$value`, is the result of the original function `.f` applied to its inputs. The second element, `$log` is `NULL` in case everything goes well. In case of error/warning/message, `$value` is NA and `$log` holds the message. `purely()` is used by `record()` to allow the latter to handle errors.

Arguments

.f

A function to decorate.

strict

Controls if the decorated function should catch only errors (1), errors and warnings (2, the default) or errors, warnings and messages (3).

Examples

Run this code
purely(log)(10)
purely(log)(-10)
purely(log, strict = 1)(-10) # This produces a warning, so with strict = 1 nothing gets captured.

Run the code above in your browser using DataLab