Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vdiffr vs testthat::expect_snapshot() for plots #1973

Closed
fh-mthomson opened this issue Jul 17, 2024 · 2 comments
Closed

vdiffr vs testthat::expect_snapshot() for plots #1973

fh-mthomson opened this issue Jul 17, 2024 · 2 comments

Comments

@fh-mthomson
Copy link

Is vdiffr still recommended over testthat::expect_snapshot() for testing plots (e.g., ggplot2 objects)?

I assume yes (per #617 (comment), #1265 (comment)) but wanted to confirm, since testthat has seen a lot of great enhancements in the snapshot realm :)

Motivating example (modified from #1393): I was hoping (perhaps naively) to use:

test_that("ggplot", {
  library(ggplot2)
  expect_snapshot(ggplot(data.frame(), aes(1,2)) + geom_point())
})

But, this errors:

── Error ('test-ggplot.R:4:3'): ggplot ─────────────────────────────────────────
Error in `UseMethod("snapshot_replay", x)`: no applicable method for 'snapshot_replay' applied to an object of class "recordedplot"
Backtrace:
    ▆
 1. └─testthat::expect_snapshot(ggplot(data.frame(), aes(1, 2)) + geom_point()) at test-ggplot.R:4:3
 2.   ├─testthat:::with_is_snapshotting(...)
 3.   └─testthat:::verify_exec(quo_get_expr(x), quo_get_env(x), replay)
 4.     ├─base::unlist(lapply(results, replay))
 5.     └─base::lapply(results, replay)
 6.       └─testthat (local) FUN(X[[i]], ...)
 7.         └─testthat:::snapshot_replay(x, state, transform = transform, cnd_class = cnd_class)
@fh-mthomson
Copy link
Author

Upon further evaluation, vdiffr has a lot of amazing features to enable comparisons across snapshots (side by side, slider, etc), so will use that indefinitely!

@hadley
Copy link
Member

hadley commented Oct 22, 2024

Yes, vdiffr is definitely recommended for graphics.

@hadley hadley closed this as completed Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants