What is the message() function in R?

Overview

R’s message() function generates diagnostic messages that are not errors or warnings.

Syntax

message(…, domain = NULL, appendLF = TRUE)
Syntax for the message() function in R

Parameter value

The message() function takes the following parameter values:

  • ...: This is a form of string(s) that is to be pasted together with no separator. This is a required parameter.
  • domain: This represents the domain for the translation. This is an optional parameter.
  • appendLF: This takes a logical value indicating whether the messages given as a character string should have a newline appended or not. This is an optional parameter.

Example

# Code to illustrate the message() function
message("Thirty four")
message("Apple", "Banana", "Pineapple")

Explanation

  • Line 2: We use the message() function to return the character string passed to it as an argument.
  • Line 3: We use the message() function to return string characters pasted together with no separator.

Why use the message() function?

The message() function is better than the paste() function when we want to concatenate strings, as it is shorter to write.

Example

message("a", "b", "c")
print(paste0("a", "b", "C"))

Explanation

Line 1–2: We compare the message() and the paste() function.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources