vdiffr
Visual regression testing and graphical diffing with testthat
Science Score: 23.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
1 of 20 committers (5.0%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.6%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Visual regression testing and graphical diffing with testthat
Basic Info
- Host: GitHub
- Owner: r-lib
- License: other
- Language: C++
- Default Branch: main
- Homepage: https://vdiffr.r-lib.org
- Size: 2.81 MB
Statistics
- Stars: 192
- Watchers: 5
- Forks: 31
- Open Issues: 9
- Releases: 18
Topics
Metadata Files
README.md
vdiffr
vdiffr is a testthat extension for monitoring the appearance of R plots. It generates reproducible SVG files and registers them as testthat snapshots.
How to use vdiffr
1) Add graphical expectations by including expect_doppelganger() in your test files.
1) Run devtools::test().
1) If test() detected new snapshots or changes to existing snapshots, run testthat::snapshot_review() to review them.
There may be many reasons for a snapshot to fail. Upstream changes (e.g. to the R graphics engine or to ggplot2) may cause subtle differences in your plots that are not actual failures. For this reason, snapshots do not cause failures on CRAN by default. You will only see failures locally or on CI platforms such as Github Actions.
Adding expectations
vdiffr integrates with testthat through the expect_doppelganger() expectation. It takes as arguments:
A title. This title is used in two ways. First, the title is standardised (it is converted to lowercase and any character that is not alphanumeric or a space is turned into a dash) and used as filename for storing the figure. Secondly, with ggplot2 figures the title is automatically added to the plot with
ggtitle()(only if no ggtitle has been set).A figure. This can be a ggplot object, a recorded plot, a function to be called, or more generally any object with a
printmethod.
The snapshots are recorded in subfolders of the _snaps/ directory.
```r disphistbase <- function() hist(mtcars$disp) disphistggplot <- ggplot(mtcars, aes(disp)) + geom_histogram()
vdiffr::expectdoppelganger("Base graphics histogram", disphistbase) vdiffr::expectdoppelganger("ggplot2 histogram", disphistggplot) ```
Note that in addition to automatic ggtitles, ggplot2 figures are
assigned the minimalistic theme theme_test() (unless they already
have been assigned a theme).
Debugging
It is sometimes difficult to understand the cause of a doppelganger failure. A frequent cause of failure is undeterministic generation of plots. Potential culprits are:
Some of the plot components depend on random variation. Try setting a seed, for instance with
withr::local_seed().The plot depends on some system library. For instance sf plots depend on libraries like GEOS and GDAL. It might not be possible to test these plots with vdiffr (which can still be used for manual inspection, add a [testthat::skip()] before the
expect_doppelganger()call in that case).
To help you understand the causes of a failure, vdiffr automatically logs the SVG diff of all failures when run under R CMD check. The log is located in tests/vdiffr.Rout.fail and should be displayed in your CI logs.
You can also set the VDIFFR_LOG_PATH environment variable with Sys.setenv() to unconditionally (also interactively) log failures in the file pointed by the variable.
Skipping all vdiffr checks on some platforms
See ggplot2's approach which wraps expect_doppelganger() with a version that that calls testthat::skip() on the relevant platforms (as determined by environment variables): https://github.com/tidyverse/ggplot2/blob/ddd207e926cc1c1847dc661d9a099b8ec19c4010/tests/testthat/helper-vdiffr.R#L1-L15.
Building vdiffr
This section is only relevant for building vdiffr from scratch, as opposed to installing from a pre-built package on CRAN.
Building vdiffr requires the system dependency libpng. As vdiffr doesn't have any build-time configuration, your R configuration must point to libpng's include and lib folders.
For instance on macOS, install libpng with:
sh
brew install libpng
And make sure your ~/.R/Makevars knows about Homebrew's include and lib folders where libpng should now be installed. On arm64 hardware, this would be:
mk
CPPFLAGS += -I/opt/homebrew/include
LDFLAGS += -L/opt/homebrew/lib
Owner
- Name: R infrastructure
- Login: r-lib
- Kind: organization
- Repositories: 154
- Profile: https://github.com/r-lib
GitHub Events
Total
- Create event: 2
- Release event: 1
- Issues event: 18
- Watch event: 8
- Delete event: 3
- Issue comment event: 14
- Push event: 29
- Pull request event: 5
Last Year
- Create event: 2
- Release event: 1
- Issues event: 18
- Watch event: 8
- Delete event: 3
- Issue comment event: 14
- Push event: 29
- Pull request event: 5
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Lionel Henry | l****y@g****m | 358 |
| Thomas Lin Pedersen | t****5@g****m | 6 |
| Nate | n****y@g****m | 5 |
| Carson Sievert | c****1@g****m | 3 |
| Dana Seidel | d****l@b****u | 2 |
| Hiroaki Yutani | y****i@g****m | 2 |
| Jeroen Ooms | j****s@g****m | 2 |
| KZARCA | k****a@g****m | 2 |
| Mara Averick | m****k@g****m | 2 |
| Maëlle Salmon | m****n@y****e | 2 |
| Christophe Dervieux | c****x@g****m | 1 |
| Dewey Dunnington | d****y@f****t | 1 |
| Evgeni Chasnovski | e****i@g****m | 1 |
| Gordon Shotwell | g****l@g****m | 1 |
| Greg Lin | g****n@r****m | 1 |
| Gregory R. Warnes | g****s@m****m | 1 |
| Ilari Scheinin | i****n@g****m | 1 |
| Kara Woo | k****o | 1 |
| Michael Chirico | m****4@g****m | 1 |
| maksymis | 3****s | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 84
- Total pull requests: 36
- Average time to close issues: about 1 year
- Average time to close pull requests: 7 months
- Total issue authors: 48
- Total pull request authors: 19
- Average comments per issue: 2.92
- Average comments per pull request: 1.33
- Merged pull requests: 28
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 4
- Pull requests: 3
- Average time to close issues: about 2 months
- Average time to close pull requests: 1 day
- Issue authors: 4
- Pull request authors: 1
- Average comments per issue: 0.25
- Average comments per pull request: 0.33
- Merged pull requests: 3
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- hadley (11)
- lionel- (8)
- IndrajeetPatil (4)
- njtierney (4)
- yutannihilation (4)
- thomasp85 (3)
- gavinsimpson (3)
- jtlandis (2)
- r2evans (2)
- pat-s (2)
- echasnovski (2)
- clauswilke (2)
- jgabry (2)
- gustavdelius (1)
- krlmlr (1)
Pull Request Authors
- lionel- (11)
- thomasp85 (4)
- yutannihilation (2)
- nathancday (2)
- maksymiuks (2)
- maelle (2)
- batpigandme (1)
- jimhester (1)
- ilarischeinin (1)
- pmur002 (1)
- GShotwell (1)
- paleolimbot (1)
- cpsievert (1)
- cderv (1)
- echasnovski (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 2
-
Total downloads:
- cran 83,747 last-month
- Total docker downloads: 150,388
-
Total dependent packages: 284
(may contain duplicates) -
Total dependent repositories: 610
(may contain duplicates) - Total versions: 28
- Total maintainers: 1
cran.r-project.org: vdiffr
Visual Regression Testing and Graphical Diffing
- Homepage: https://vdiffr.r-lib.org/
- Documentation: http://cran.r-project.org/web/packages/vdiffr/vdiffr.pdf
- License: MIT + file LICENSE
-
Latest release: 1.0.8
published over 1 year ago
Rankings
Maintainers (1)
conda-forge.org: r-vdiffr
- Homepage: https://vdiffr.r-lib.org/
- License: MIT
-
Latest release: 1.0.4
published almost 4 years ago
Rankings
Dependencies
- R >= 3.2.0 depends
- diffobj * imports
- glue * imports
- grDevices * imports
- htmltools * imports
- lifecycle * imports
- rlang * imports
- testthat >= 3.0.3 imports
- xml2 >= 1.0.0 imports
- covr * suggests
- ggplot2 >= 3.2.0 suggests
- roxygen2 * suggests
- withr * suggests
- testthat * suggests
- vdiffr * suggests
- actions/checkout v2 composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
- JamesIves/github-pages-deploy-action 4.1.4 composite
- actions/checkout v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
- actions/checkout v2 composite
- r-lib/actions/pr-fetch v2 composite
- r-lib/actions/pr-push v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
- actions/checkout v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite