Learn R Programming

rbmi (version 1.4.1)

record: Capture all Output

Description

This function silences all warnings, errors & messages and instead returns a list containing the results (if it didn't error) + the warning and error messages as character vectors.

Usage

record(expr)

Value

A list containing

  • results - The object returned by expr or list() if an error was thrown

  • warnings - NULL or a character vector if warnings were thrown

  • errors - NULL or a string if an error was thrown

  • messages - NULL or a character vector if messages were produced

Arguments

expr

An expression to be executed

Examples

Run this code
if (FALSE) {
record({
  x <- 1
  y <- 2
  warning("something went wrong")
  message("O nearly done")
  x + y
})
}

Run the code above in your browser using DataLab