cnd_muffle {rlang}R Documentation

Muffle a condition

Description

Unlike exiting() handlers, calling() handlers must be explicit that they have handled a condition to stop it from propagating to other handlers. Use cnd_muffle() within a calling handler (or as a calling handler, see examples) to prevent any other handlers from being called for that condition.

Usage

cnd_muffle(cnd)

Arguments

cnd

A condition to muffle.

Value

If cnd is mufflable, cnd_muffle() jumps to the muffle restart and doesn't return. Otherwise, it returns FALSE.

Mufflable conditions

Most conditions signalled by base R are muffable, although the name of the restart varies. cnd_muffle() will automatically call the correct restart for you. It is compatible with the following conditions:

If you call cnd_muffle() with a condition that is not mufflable you will cause a new error to be signalled.

Examples

Run examples

fn <- function() {
  inform("Beware!", "my_particular_msg")
  inform("On your guard!")
  "foobar"
}

# Let's install a muffling handler for the condition thrown by `fn()`.
# This will suppress all `my_particular_wng` warnings but let other
# types of warnings go through:
with_handlers(fn(),
  my_particular_msg = calling(function(cnd) {
    inform("Dealt with this particular message")
    cnd_muffle(cnd)
  })
)

# Note how execution of `fn()` continued normally after dealing
# with that particular message.

# cnd_muffle() can also be passed to with_handlers() as a calling
# handler:
with_handlers(fn(),
  my_particular_msg = calling(cnd_muffle)
)

[Package rlang version 1.1.4 Index]