# NOT RUN {
# Write a function that stops the function
# with a message with the requested number
# of info lines
yield_an_error <- function(msgs) {
if (msgs > 3) msgs <- 3
# Create some strings can serve as additional
# info for the message
message_components <-
c("* message info 1",
"* message info 2",
"* message info 3")
# Generate and emit a formatted message
emit_error(
"There (is/are) {number} thing(s) to note",
message_components[1:msgs],
number = msgs,
.format = "{.f_name} info: {text}")
}
# When that function is called, a formatted
# message will appear; here are some examples:
yield_an_error(msgs = 3)
#> Error: `yield_an_error()` info: There are 3 things to note
#> * message info 1
#> * message info 2
#> * message info 3
yield_an_error(msgs = 2)
#> Error: `yield_an_error()` info: There are 2 things to note
#> * message info 1
#> * message info 2
yield_an_error(msgs = 1)
#> Error: `yield_an_error()` info: There is 1 thing to note
#> * message info 1
# }
Run the code above in your browser using DataLab