tests/testthat/examples/knitr-examples/117-messages.md

title: "Merging messages"

Different messages are placed in separate blocks:

f = function() {
    message("Hello")
    message("World!")
}
f()
## Hello
## World!

Consecutive identical messages are automatically merged into a single block:

f1 = function() {
    for (i in 1:5) message("Hello")
}
f1()
## Hello
## Hello
## Hello
## Hello
## Hello
f2 = function() {
    for (i in 1:5) warning("Hello")
}
f2()
## Warning in f2(): Hello
## Warning in f2(): Hello
## Warning in f2(): Hello
## Warning in f2(): Hello
## Warning in f2(): Hello

A message in message(..., appendLF = FALSE) will be merged with the next adjacent message:

f3 = function() {
    message("Hello ", appendLF = FALSE)
    message("World!")
}
f3()
## Hello World!


Try the parsermd package in your browser

Any scripts or data that you put into this service are public.

parsermd documentation built on Aug. 21, 2025, 5:27 p.m.