capture_output: Capture output to console

Description Usage Arguments Details Value Examples

View source: R/capture-output.R

Description

Evaluates code in a special context in which all output is captured, similar to capture.output().

Usage

1
2
3
4
5

Arguments

code

Code to evaluate.

print

If TRUE and the result of evaluating code is visible, print the result using testthat_print().

width

Number of characters per line of output. This does not inherit from getOption("width") so that tests always use the same output width, minimising spurious differences.

Details

Results are printed using the testthat_print() generic, which defaults to print(), giving you the ability to customise the printing of your object in tests, if needed.

Value

capture_output() returns a single string. capture_output_lines() returns a character vector with one entry for each line

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
capture_output({
  cat("Hi!\n")
  cat("Bye\n")
})

capture_output_lines({
  cat("Hi!\n")
  cat("Bye\n")
})

capture_output("Hi")
capture_output("Hi", print = TRUE)

r-lib/testthat documentation built on Sept. 25, 2021, 3:02 p.m.