vdiffr (version 0.1.0)

expect_doppelganger: Does a figure look like its expected output?

Description

If the test has never been validated yet, the test is skipped. If the test has previously been validated but fig does not look like its expected output, an error is issued. Use validate_cases() or manage_cases() to (re)validate the test.

Usage

expect_doppelganger(title, fig, path = NULL, ..., user_fonts = NULL)

Arguments

title
The figure title is used for creating the figure file names (all non-alphanumeric characters are converted to -). Also, ggplot2 figures are appended with ggtitle(title).
fig
A figure to test.
path
The path where the test case should be stored, relative to the tests/figs/ folder. If NULL (the default), the current testthat context is used to create a subfolder. Supply an empty string "" if you want the figures to be stored in the root folder.
...
Additional arguments passed to compare() to control specifics of comparison.
user_fonts
Passed to svglite() to make sure SVG are reproducible. Defaults to Liberation fonts for standard families and Symbola font for symbols.

Details

fig can be a ggplot object, a recordedplot, a function to be called, or more generally any object with a print method. If a ggplot object, a dependency for ggplot2 is automatically added (see add_dependency()).

Examples

Run this code
disp_hist_base <- function() hist(mtcars$disp)
expect_doppelganger("disp-histogram-base", disp_hist_base)

if (requireNamespace("ggplot2", quietly = TRUE)) {
  library("ggplot2")
  disp_hist_ggplot <- ggplot(mtcars, aes(disp)) + geom_histogram()
  expect_doppelganger("disp-histogram-ggplot", disp_hist_ggplot)
}

Run the code above in your browser using DataCamp Workspace