README.md

waldo

Codecov test
coverage R-CMD-check

The goal of waldo is to find and concisely describe the difference between a pair of R objects, with the primary goal of making it easier to figure out what’s gone wrong in your unit tests.

waldo::compare() is inspired by all.equal(), but takes additional care to generate actionable insights by:

Installation

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

install.packages("waldo")

Comparisons

library(waldo)

When comparing atomic vectors, compare() produces diffs (thanks to diffobj) that highlight additions, deletions, and changes, along with a little context:

r compare(c("a", "b", "c"), c("a", "b"))

r compare(c("a", "b"), c("a", "b", "c"))

r compare(c("a", "b", "c"), c("a", "B", "c"))

r compare(c("X", letters), c(letters, "X"))

Depending on the relative size of the differences and the width of your console you’ll get one of three displays:

r compare(letters[1:5], letters[1:6])

r options(width = 20) compare(letters[1:5], letters[1:6])

r options(width = 10) compare(letters[1:5], letters[1:6])

When comparing more complex objects, waldo creates an executable code path telling you where the differences lie:

r compare(list(factor("x")), list(1L))

r df1 <- data.frame(x = 1:3, y = 3:1) df2 <- tibble::tibble(rev(df1)) compare(df1, df2)

r x <- list(a = list(b = list(c = list(structure(1, e = 1))))) y <- list(a = list(b = list(c = list(structure(1, e = "a"))))) compare(x, y)



Try the waldo package in your browser

Any scripts or data that you put into this service are public.

waldo documentation built on Nov. 2, 2023, 5:39 p.m.