dazdiff

dazdiff compares two tables value by value and returns one row per compared value, traced back to its source row in both tables.

Installation

Install the released version from CRAN:

install.packages("dazdiff")

Or the development version from GitHub:

# install.packages("pak")
# pak::pak("pedrobtz/dazdiff")
install.packages("dazdiff", repos = c('https://pedrobtz.r-universe.dev', 'https://cloud.r-project.org'))

Usage

A table, and the same data after a round trip through storage: the names changed case, the ids became text, one amount moved and one row was replaced. diff_table() pairs the rows on id and compares amount:

library(dazdiff)

benchmark <- data.frame(id = 1:3, amount = c(100, 200, 300))
stored <- data.frame(ID = c("1", "2", "4"), Amount = c(100, 200.5, 400))

diff_table(benchmark, stored, by = "id")
#> Key: <ID, metric>
#>       ID metric row_id_x row_id_y value_x value_y  diff abs_diff    rel_diff  status
#>    <int> <char>    <int>    <int>   <num>   <num> <num>    <num>       <num>  <fctr>
#> 1:     1 AMOUNT        1        1     100   100.0   0.0      0.0 0.000000000    same
#> 2:     2 AMOUNT        2        2     200   200.5   0.5      0.5 0.002493766 changed
#> 3:     3 AMOUNT        3       NA     300      NA    NA       NA          NA  only_x
#> 4:     4 AMOUNT       NA        3      NA   400.0    NA       NA          NA  only_y

Column names are normalized to upper case, which is how id pairs with ID. status says what happened to each value, and row_id_x and row_id_y are its rows in the two tables.

dazdiff also summarizes and draws a comparison, finds which keys hold the differences, compares two tables as equals, and works as a testthat expectation. Get started shows each of these.

Learn more