Learn R Programming

gridGraphics (version 0.5-1)

plotdiff: Test for identical output from grid.echo()

Description

Functions to generate a scene using the graphics package, reproduce the scene using grid.echo(), test whether the two results are identical, and report on any differences.

Usage

plotdiff(expr, label, dev = "pdf",
         antialias = TRUE, density = 100, width = 7, height = 7)
plotdiffInit()
plotdiffResult(warn = FALSE)

Arguments

expr

An expression that draws something using the graphics package.

label

A character value that is used to label files generated during testing.

dev

The graphics device used for drawing and echoing. Currently can only be either "pdf" or "png".

antialias

A logical value indicating whether to perform antialiasing when converting from PDF to PNG.

density

A numeric value indicating the resolution (dpi) to use when converting from PDF to PNG.

width, height

Numeric values indicating the size of the device to test on.

warn

A logical value indicating whether non-identical output should produce a warning or an error.

Value

All functions are run for their side effects. In the case of plotdiff(), the generation of PDF and PNG files and the accumulation of differences about messages. In the case of plotdiffResult(), a print out of the accumulated messages, plus possibly either an error or warning.

Details

In default usage, plotdiff() is used to generate two PDF files, one using the original expression and the other from a call to grid.echo(). The PDF files are then converted to PNG files and the PNG files are compared (using ImageMagick). If there are any differences, the comparison generates a further PNG file that shows the differences.

All files are currently generated in the current working directory.

Text messages are also generated by plotdiff() whenever a difference is found, but those messages are stored up rather than printed immediately. The plotdiffResult() function prints out all messages since the last call to plotdiffInit().

Standard usage involves calling plotdiffInit(), followed by one or more plotdiff() calls, then finally a call to plotdiffResult(). Examples of the usage of these functions are provided in the numerous test scripts in the test-scripts directory of the package.

See Also

grid.echo

Examples

Run this code
# NOT RUN {
plotdiff(expression(plot(1)), "plot")
# }

Run the code above in your browser using DataLab