Learn R Programming

rlang (version 1.1.3)

cnd_signal: Signal a condition object

Description

cnd_signal() takes a condition as argument and emits the corresponding signal. The type of signal depends on the class of the condition:

  • A message is signalled if the condition inherits from "message". This is equivalent to signalling with inform() or base::message().

  • A warning is signalled if the condition inherits from "warning". This is equivalent to signalling with warn() or base::warning().

  • An error is signalled if the condition inherits from "error". This is equivalent to signalling with abort() or base::stop().

  • An interrupt is signalled if the condition inherits from "interrupt". This is equivalent to signalling with interrupt().

Usage

cnd_signal(cnd, ...)

Arguments

cnd

A condition object (see cnd()). If NULL, cnd_signal() returns without signalling a condition.

...

These dots are for future extensions and must be empty.

See Also

  • cnd_type() to determine the type of a condition.

  • abort(), warn() and inform() for creating and signalling structured R conditions in one go.

  • try_fetch() for establishing condition handlers for particular condition classes.

Examples

Run this code
# The type of signal depends on the class. If the condition
# inherits from "warning", a warning is issued:
cnd <- warning_cnd("my_warning_class", message = "This is a warning")
cnd_signal(cnd)

# If it inherits from "error", an error is raised:
cnd <- error_cnd("my_error_class", message = "This is an error")
try(cnd_signal(cnd))

Run the code above in your browser using DataLab