From henr|k@bengt@@on @end|ng |rom gm@||@com  Tue Mar  1 19:38:57 2022
From: henr|k@bengt@@on @end|ng |rom gm@||@com (Henrik Bengtsson)
Date: Tue, 1 Mar 2022 10:38:57 -0800
Subject: [Rd] message(<cond>) and warning(<cond>) circumvent calling
 handlers and signal the original class, e.g. an error
Message-ID: <CAFDcVCTBnYeL_7Gi17b8azZXyybTK7LZ380bb8Ko5EaqB2R0ow@mail.gmail.com>

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)
boom!

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))
boom!

or captured with calling handlers, e.g.

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

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
warning(<error>).

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

/Henrik

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



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