Compare two objects
This compares two R objects, identifying the key differences. It:
Orders the differences from most important to least important.
Displays the values of atomic vectors that are actually different.
Carefully uses colour to emphasise changes (while still being readable when colour isn't available).
Uses R code (not a text description) to show where differences arise.
Where possible, it compares elements by name, rather than by position.
Errs on the side of producing too much output, rather than too little.
compare()
is an alternative to all.equal()
.
compare( x, y, ..., x_arg = "old", y_arg = "new", tolerance = NULL, max_diffs = if (in_ci()) Inf else 10, ignore_srcref = TRUE, ignore_attr = FALSE, ignore_encoding = TRUE, ignore_function_env = FALSE, ignore_formula_env = FALSE )
x, y |
Objects to compare. |
... |
A handful of other arguments are supported with a warning for backward compatability. These include:
All other arguments are ignored with a warning. |
x_arg, y_arg |
Name of |
tolerance |
If non- It uses the same algorithm as |
max_diffs |
Control the maximum number of differences shown. The
default shows 10 differences when run interactively and all differences
when run in CI. Set |
ignore_srcref |
Ignore differences in function |
ignore_attr |
Ignore differences in specified attributes? Supply a character vector to ignore differences in named attributes. For backward compatibility with |
ignore_encoding |
Ignore string encoding? |
ignore_function_env, ignore_formula_env |
Ignore the environments of
functions and formulas, respectively? These are provided primarily for
backward compatibility with |
A character vector with class "waldo_compare". If there are no differences it will have length 0; otherwise each element contains the description of a single difference.
# Thanks to diffobj package comparison of atomic vectors shows differences # with a little context compare(letters, c("z", letters[-26])) compare(c(1, 2, 3), c(1, 3)) compare(c(1, 2, 3), c(1, 3, 4, 5)) compare(c(1, 2, 3), c(1, 2, 5)) # More complex objects are traversed, stopping only when the types are # different compare( list(x = list(y = list(structure(1, z = 2)))), list(x = list(y = list(structure(1, z = "a")))) ) # Where possible, recursive structures are compared by name compare(iris, rev(iris)) compare(list(x = "x", y = "y"), list(y = "y", x = "x")) # Otherwise they're compared by position compare(list("x", "y"), list("x", "z")) compare(list(x = "x", x = "y"), list(x = "x", y = "z"))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.