message
Overview
message() sends diagnostic output to the stderr() connection. Unlike stop(), it does not halt the function that calls it. Unlike warning(), it does not mark the output as exceptional. It is purely informational output that a user or developer sees as the program runs.
You will encounter message() in three situations: when writing your own functions, when suppressing messages from others’ code, and when R itself reports package loading progress. message() is the lowest-key output mechanism R provides — it exists to tell you something without implying anything is wrong.
Signature
message(…, domain = NULL, appendLF = TRUE)
suppressMessages(expr)
packageStartupMessage(…, domain = NULL, appendLF = TRUE)
Parameters
| Parameter | Description |
|---|---|
… | One or more objects. R coerces each to character and pastes them together with no separator. A single condition object is also accepted as the only argument. |
domain | Passed to gettext() for localization. Set NA to skip translation lookup. |
appendLF | Logical. When TRUE (the default), R appends a newline after the message text. Set FALSE to keep output on the same line as subsequent output. |
expr | An expression. suppressMessages() evaluates it in a context where all message() calls are silenced. |
Return Value
message() returns NULL invisibly. It is called purely for its side effect.
Basic Usage
message("Data import complete")
# Stderr: Data import complete
Concatenating values without separators trips up new R users. R pastes the arguments together directly:
message("User ", username, " logged in at ", Sys.time())
# Stderr: User alice logged in at 2026-01-15 10:30:00
To suppress output on the same line, use appendLF = FALSE:
message("Loading: 75%", appendLF = FALSE)
cat(" [done]\n")
# Stderr: Loading: 75% [done]
Suppressing Messages
Wrap code in suppressMessages() to hide all message() calls during evaluation:
suppressMessages(message("This will not appear"))
# No output
This only suppresses message() calls. Warnings and errors pass through unchanged. To suppress those too, use suppressWarnings() or tryCatch() respectively.
Condition Objects
message() accepts a condition object as its sole argument. When you do this, additional arguments are silently ignored and a warning is raised:
my_cond <- simpleMessage("condition message")
message(my_cond)
# This works but ignores any other arguments passed alongside
For custom condition handling, tryCatch() or withCallingHandlers() give you more control. The muffleMessage restart is active while a message is being processed, letting you intercept it programmatically.
Messages vs Warnings vs Errors
| Function | Execution continues | Output destination | Use case |
|----------|--------------------|--------------------|
| message() | Yes | stderr | Progress, debug, informational |
| warning() | Yes | stderr | Something unexpected but recoverable |
| stop() | No | stderr | Fatal error, code must stop |
The practical difference between message() and warning() is that warnings can be promoted to errors via options(warn = 2), and the R documentation explicitly represents messages and warnings as distinct condition types. A messageCondition is not the same as a warningCondition.
Package Startup Messages
packageStartupMessage() is designed for package loading output. It behaves like message() but is specifically intended for boot-time diagnostics:
# In a package's .onLoad function:
packageStartupMessage("Loading myPackage v1.0")
suppressPackageStartupMessages() suppresses only these startup messages:
suppressPackageStartupMessages(library(myPackage))
Common Mistakes
Confusing message() with stop(). message() does not halt execution. If you want to stop with an error message, use stop():
# Wrong: thinking message() stops the code
message("File not found")
# Code continues past this point
# Right: stop() halts execution
stop("File not found")
Writing to the wrong stream. message() sends to stderr(), not stdout(). This matters when redirecting output:
# stdout redirect misses message() output
system2("Rscript", args = c("-e", "message('hi')"), stdout = "out.txt", stderr = "err.txt")
# 'hi' appears in err.txt, not out.txt
Assuming suppressMessages() hides warnings. It does not:
suppressMessages(warning("This warning still appears"))
# [1] This warning still appears
See Also
/reference/base-functions/stop/ /reference/base-functions/warning/ /reference/base-functions/cat/