Closed batpigandme closed 1 year ago
message_cnd()
creates a condition object that inherits from "message"
but doesn't emit it. Were you looking for inform()
or message()
?
🤦 Duh! Sorry, @lionel-!
Your call re. message()
vs inform()
, since it seems to work pretty much the same with both as long as global_entrace()
is enabled (I'm sure you understand the subtle differences infinitely better than I do).
Faux reprex to avoid the #> Error in globalCallingHandlers(error = function (cnd) : should not be called with handlers on the stack
:
With message()
library(rlang)
global_entrace()
f <- function() { message("Hey!"); g() }
g <- function() { message("Hi!"); h() }
h <- function() message("Hello!")
f()
#> Hey!
#> Hi!
#> Hello!
rlang::last_messages()
#> [[1]]
#> <message/rlang_message>
#> Message in `message()`:
#> Hey!
#> ---
#> Backtrace:
#> 1. global f()
#>
#> [[2]]
#> <message/rlang_message>
#> Message in `message()`:
#> Hi!
#> ---
#> Backtrace:
#> 1. global f()
#> 2. global g()
#>
#> [[3]]
#> <message/rlang_message>
#> Message in `message()`:
#> Hello!
#> ---
#> Backtrace:
#> 1. global f()
#> 2. global g()
#> 3. global h()
With inform()
library(rlang)
global_entrace()
f <- function() { inform("Hey!"); g() }
g <- function() { inform("Hi!"); h() }
h <- function() inform("Hello!")
f()
#> Hey!
#> Hi!
#> Hello!
rlang::last_messages()
#> [[1]]
#> <message/rlang_message>
#> Message:
#> Hey!
#> ---
#> Backtrace:
#> 1. global f()
#>
#> [[2]]
#> <message/rlang_message>
#> Message:
#> Hi!
#> ---
#> Backtrace:
#> 1. global f()
#> 2. global g()
#>
#> [[3]]
#> <message/rlang_message>
#> Message:
#> Hello!
#> ---
#> Backtrace:
#> 1. global f()
#> 2. global g()
#> 3. global h()
Currently the examples for Display last warnings which references both
last_warnings()
andlast_messages()
doesn't have any examples forlast_messages()
.I'm trying to figure out where I'm going wrong in my attempts to use
last_messages()
, and having an example of how it should work would probably help me (and others) get there.I think I finally got it in the end (I was messing things up by leaving the
immediate. = TRUE
arg from the warnings example in the code for the messages), but it took me a hot second (and I'm, not sure if there's supposed to be a stack of messages as there were for warnings):Faux reprex (since output changes when you use Rmarkdown:
Created on 2023-02-27 with reprex v2.0.2