expect_doppelganger

0th

Percentile

Does a figure look like its expected output?

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,
  verbose = FALSE)
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.

verbose

If TRUE, the contents of the SVG files for the comparison plots are printed during testthat checks. This is useful to investigate errors when testing remotely.

Note that it is not possible to print the original SVG during interactive use. This is because there is no way of figuring out in which directory this SVG lives. Consequently, only the test case is printed.

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()).

Aliases
  • expect_doppelganger
Examples
# NOT RUN {
ver <- gdtools::version_freetype()

if (ver >= "2.6.0") {
  disp_hist_base <- function() hist(mtcars$disp)
  expect_doppelganger("disp-histogram-base", disp_hist_base)
}

if (ver >= "2.6.0" && requireNamespace("ggplot2", quietly = TRUE)) {
  library("ggplot2")
  disp_hist_ggplot <- ggplot(mtcars, aes(disp)) + geom_histogram()
  expect_doppelganger("disp-histogram-ggplot", disp_hist_ggplot)
}
# }
Documentation reproduced from package vdiffr, version 0.2.0, License: GPL-3 | file LICENSE

Community examples

Looks like there are no examples yet.