Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

expect_known_display

Test helpers


Description

[Superseded]

Expectation for packages that implement a data type with pillar support. Allows storing the desired result in a file, and comparing the output with the file contents. Note that this expectation sets options that affect the formatting of the pillar, see examples for usage.

Usage

expect_known_display(object, file, ..., width = 80L, crayon = TRUE)

Arguments

object

An object to check.

file

File path where known value/output will be stored.

...

Unused.

width

The width of the output.

crayon

Color the output?

Life cycle

This function is deprecated in favor of testthat::expect_snapshot(). If your package uses the third edition of testthat, do not use this function.

Examples

file <- tempfile("pillar", fileext = ".txt")

# The pillar is constructed after options have been set
# (need two runs because reference file doesn't exist during the first run)
suppressWarnings(tryCatch(
  expect_known_display(pillar(1:3), file, crayon = FALSE),
  expectation_failure = function(e) {}
))
expect_known_display(pillar(1:3), file, crayon = FALSE)

# Good: Use tidyeval to defer construction
pillar_quo <- rlang::quo(pillar(1:3))
expect_known_display(!!pillar_quo, file, crayon = FALSE)

## Not run: 
# Bad: Options set in the active session may affect the display
integer_pillar <- pillar(1:3)
expect_known_display(integer_pillar, file, crayon = FALSE)

## End(Not run)

pillar

Coloured Formatting for Columns

v1.6.0
MIT + file LICENSE
Authors
Kirill Müller [aut, cre], Hadley Wickham [aut], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.