The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

snapr snapr hex sticker

R-CMD-check Codecov test coverage CRAN checks License: MIT

The goal of snapr is to provide convenient snapshot testing functions for R packages:

Installation

You can install the released version of snapr from CRAN with:

install.packages("snapr")

You can install the development version of snapr from GitHub with:

# install.packages("pak")
pak::pak("d-morrison/snapr")

Optional: enhanced RDS diffs with diffviewer

snapr works best with the d-morrison/diffviewer fork of diffviewer, which wraps diffobj to provide rich, visual diffs when reviewing RDS snapshots via testthat::snapshot_review(). Install it with:

pak::pak("d-morrison/diffviewer")

Examples

Snapshot data.frames

library(snapr)

# In a testthat test file:
test_that("iris data is correct", {
  expect_snapshot_data(iris[1:5, ], name = "iris_sample")
})

Snapshot any R object

library(snapr)

# Snapshot a list (RDS format by default - works for any R object)
test_that("config object is correct", {
  config <- list(
    name = "my_app",
    version = "1.0.0",
    settings = list(debug = TRUE, timeout = 30)
  )
  expect_snapshot_object(config, name = "config")
})

# Snapshot with JSON format for human-readable diffs
test_that("simple data is correct", {
  data <- list(x = 1:5, y = letters[1:5])
  expect_snapshot_object(data, name = "simple_data", writer = save_json)
})

# Snapshot a model (use RDS for complex objects)
test_that("model structure is correct", {
  model <- lm(mpg ~ wt, data = mtcars)
  expect_snapshot_object(model, name = "model")
})

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.