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.




A condition to muffle.


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.

  • Errors are not mufflable since they are signalled in critical situations where execution cannot continue safely.

  • Conditions captured with base::tryCatch(), with_handlers() or catch_cnd() are no longer mufflable. Muffling restarts must be called from a calling handler.


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) }) )
#> Dealt with this particular message
#> On your guard!
#> [1] "foobar"
# 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) )
#> On your guard!
#> [1] "foobar"