The message() function

Defensive R Programming

Dr. Colin Gillespie

Jumping Rivers

The message() function

  • Signals to the user the state of a process
  • This isn't an error - it's just helpful information
  • For example, suppose you're running cross-validation, then output could be
CV 1 of 10 complete
CV 2 of 10 complete
CV 3 of 10 complete
Defensive R Programming

We can turn it off with suppressMessages()

noisy = function(a, b) {
   message("I'm doing stuff")
   a + b
}
noisy(1, 2)
I'm doing stuff
# [1] 3
suppressMessages(noisy(1, 2))
# [1] 3
Defensive R Programming

Telling packages to be quiet

  • Occasionally, packages can be a bit noisy
  • Sometimes loading ggplot2, it presents a message
  • Don't worry, we can tell it to be quiet
suppressPackageStartupMessages(library("ggplot2"))
Defensive R Programming

Using message()

The message() function is helpful for letting

  • you
  • and other users

know what's happening.

It's very handy for long running processes

Defensive R Programming

Let's do some work!

Defensive R Programming

Preparing Video For Download...