Learn R Programming

testthat (version 2.2.1)

capture_condition: Capture conditions, including messeages, warnings, expectations, and errors.

Description

These functions allow you to capture the side-effects of a function call including printed output, messages and warnings. They are used to evaluate code for expect_output(), expect_message(), expect_warning(), and expect_silent().

Usage

capture_condition(code)

capture_error(code)

capture_expectation(code)

capture_message(code)

capture_warning(code)

capture_messages(code)

capture_warnings(code)

Arguments

code

Code to evaluate

Value

Singular functions (capture_condition, capture_expectation etc) return a condition object. capture_messages() and capture_warnings return a character vector of message text.

Examples

Run this code
# NOT RUN {
f <- function() {
  message("First")
  warning("Second")
  message("Third")
}

capture_message(f())
capture_messages(f())

capture_warning(f())
capture_warnings(f())

# Condition will capture anything
capture_condition(f())
# }

Run the code above in your browser using DataLab