[Rd] message(<cond>) and warning(<cond>) circumvent calling handlers and signal the original class, e.g. an error

Henrik Bengtsson henr|k@bengt@@on @end|ng |rom gm@||@com
Tue Mar 1 19:38:57 CET 2022

Hi, in help("message", package = "base"), we can read:

Description: 'message' is used for generating 'simple' diagnostic
messages which are neither warnings nor errors, but nevertheless
represented as conditions.

>From this, I conclude that message() should generate a condition that
are neither warning nor errors.

However, the following signals a condition of class 'error':

> e <- simpleError("boom!\n")
> message(e)

This can be seen if we do:

> res <- tryCatch(message(e), condition = identity)
> res
<simpleError: boom!

This stems from message(e) using signalCondition(e) internally.

Another problem with this behavior is that message(e) cannot be suppressed:

> suppressMessages(message(e))

or captured with calling handlers, e.g.

> res <- withCallingHandlers(message(e), condition = identity)
> res

If we replace e <- simpleError("boom") with e <-
simpleWarning("careful"), we see a similar behavior.  These problems
exist also with warning(e).  The current behaviors prevent functions
from capturing and relaying message(<error>), message(<warning>), and

I'm happy to post a bug report to <https://bugs.r-project.org/>.


PS. BTW, it looks like some recent "..." tweaks to the warning() and
stop() code could be applied also to message().

More information about the R-devel mailing list