capture_condition: Capture conditions, including messages, warnings,...

Description Usage Arguments Value Examples

Description

[Superseded]

These functions allow you to capture the side-effects of a function call including printed output, messages and warnings. We no longer recommend that you use these functions, instead relying on the expect_message() and friends to bubble up unmatched conditions. If you just want to silence unimportant warnings, use suppressWarnings().

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
capture_condition(code, entrace = FALSE)

capture_error(code, entrace = FALSE)

capture_expectation(code, entrace = FALSE)

capture_message(code, entrace = FALSE)

capture_warning(code, entrace = FALSE)

capture_messages(code)

capture_warnings(code)

Arguments

code

Code to evaluate

entrace

Whether to add a backtrace to the captured condition.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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())

Example output

<simpleMessage in message("First"): First
>
[1] "First\n" "Third\n"
Warning message:
In f() : Second
First
<simpleWarning in f(): Second>
First
Third
[1] "Second"
<simpleMessage in message("First"): First
>

testthat documentation built on Oct. 4, 2021, 9:07 a.m.