Compare multiple pairs of images in batch. Useful for visual regression testing across many screenshots.
Arguments
- pairs
A data.frame with columns
img1andimg2containing file paths, or a list of named lists withimg1andimg2elements.- diff_dir
Directory to save diff images. If
NULL, no diff images are created. If provided, diff images are named based on the input file names.- parallel
Logical; if
TRUE, compare images in parallel using multiple CPU cores. Usesparallel::mclapplyon Unix systems (macOS, Linux) and falls back to sequential processing on Windows. Default isFALSE. The number of cores is taken fromgetOption("mc.cores")(or detected), capped at the number of pairs, and limited to 2 when the_R_CHECK_LIMIT_CORES_environment variable is"TRUE"/"true"or"warn"(as duringR CMD check --as-cran).- ...
Additional arguments passed to
compare_images().
Value
A tibble (if available) or data.frame with class odiffr_batch,
containing one row per comparison with all columns from compare_images()
(including error) plus a leading pair_id column. Use summary() to
get aggregate statistics. If pairs is empty (a zero-row data.frame or
an empty list), an empty odiffr_batch with the same columns is
returned.
Details
A failure while comparing one pair (for example, a file that does not
exist, cannot be read, or has an unsupported format) does not abort the
batch. Instead, that pair is reported as a row with match = FALSE,
reason = "error", and the error message in the error column. The same
applies to failed worker processes when parallel = TRUE.
See also
summary.odiffr_batch() for summarizing batch results,
compare_image_dirs() for directory-based comparison.
Examples
if (FALSE) { # \dontrun{
# Create a data frame of image pairs
pairs <- data.frame(
img1 = c("baseline/page1.png", "baseline/page2.png"),
img2 = c("current/page1.png", "current/page2.png")
)
# Compare all pairs
results <- compare_images_batch(pairs, diff_dir = "diffs/")
# Compare in parallel (Unix only)
results <- compare_images_batch(pairs, parallel = TRUE)
# Check which comparisons failed
results[!results$match, ]
# Inspect errors (e.g. unreadable or missing files)
results[results$reason == "error", c("img1", "img2", "error")]
} # }
