Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

cnd

Create a condition object


Description

These constructors make it easy to create subclassed conditions. Conditions are objects that power the error system in R. They can also be used for passing messages to pre-established handlers.

Usage

error_cnd(class = NULL, ..., message = "", trace = NULL, parent = NULL)

cnd(class, ..., message = "")

warning_cnd(class = NULL, ..., message = "")

message_cnd(class = NULL, ..., message = "")

Arguments

class

The condition subclass.

...

<dynamic> Named data fields stored inside the condition object.

message

A default message to inform the user about the condition when it is signalled.

trace

A trace object created by trace_back().

parent

A parent condition object created by abort().

Details

cnd() creates objects inheriting from condition. Conditions created with error_cnd(), warning_cnd() and message_cnd() inherit from error, warning or message.

See Also

Examples

# Create a condition inheriting from the s3 type "foo":
cnd <- cnd("foo")

# Signal the condition to potential handlers. Since this is a bare
# condition the signal has no effect if no handlers are set up:
cnd_signal(cnd)

# When a relevant handler is set up, the signal causes the handler
# to be called:
with_handlers(cnd_signal(cnd), foo = exiting(function(c) "caught!"))

# Handlers can be thrown or executed inplace. See with_handlers()
# documentation for more on this.

# Signalling an error condition aborts the current computation:
err <- error_cnd("foo", message = "I am an error")
try(cnd_signal(err))

rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.