Odiffr provides R bindings to Odiff, a blazing-fast pixel-by-pixel image comparison tool. It’s designed for:
Odiffr requires the Odiff binary to be installed on your system:
# npm (cross-platform, recommended)
npm install -g odiff-bin
# Or download binaries from GitHub releases
# https://github.com/dmtrKovalenko/odiff/releasesIf you cannot install Odiff system-wide, use
odiffr_update() after installing the package to download a
binary to your user cache.
The main function is compare_images(), which returns a
tibble (or data.frame):
The threshold parameter (0-1) controls color sensitivity. Lower values are more precise:
Ignore antialiased pixels that often differ between renders:
Compare multiple image pairs efficiently:
Odiffr integrates with the magick package for preprocessing:
For full control, use odiff_run():
result <- odiff_run(
img1 = "baseline.png",
img2 = "current.png",
diff_output = "diff.png",
threshold = 0.1,
antialiasing = TRUE,
fail_on_layout = TRUE,
diff_mask = FALSE,
diff_overlay = 0.5,
diff_color = "#FF00FF",
diff_lines = TRUE,
reduce_ram = FALSE,
ignore_regions = list(ignore_region(10, 10, 100, 50)),
timeout = 60
)
# Detailed result
result$match
result$reason
result$diff_count
result$diff_percentage
result$diff_lines
result$exit_code
result$durationDownload the latest Odiff binary to your user cache:
Use a specific binary (useful for validated environments):
Example integration with testthat:
library(testthat)
library(odiffr)
test_that("dashboard renders correctly", {
# Generate current screenshot
webshot2::webshot("http://localhost:3838/dashboard", "current.png")
# Compare to baseline
result <- compare_images(
"baselines/dashboard.png",
"current.png",
diff_output = "diffs/dashboard_diff.png",
threshold = 0.1,
antialiasing = TRUE
)
expect_true(result$match,
info = sprintf("%.2f%% pixels differ", result$diff_percentage))
})Odiffr is designed for validated pharmaceutical/clinical research:
options(odiffr.path = ...)odiff_version() to
document binary version for audit trails