diffobj: Compare two dfs (or other objects)

dataframes
Author
Published

June 25, 2023

What’s the difference between two dfs?

diffobj::diffPrint() gives a handy visual way to check differences:

library(diffobj)

a <- b <- matrix(1:100, ncol=2)
a <- a[-20,]
b <- b[-45,]
b[c(18, 44)] <- 999

diffPrint(target=a, current=b)
< a                > b              
@@ 17,6 @@         @@ 17,7 @@       
~       [,1] [,2]  ~       [,1] [,2]
  [16,]   16   66    [16,]   16   66
  [17,]   17   67    [17,]   17   67
< [18,]   18   68  > [18,]  999   68
  [19,]   19   69    [19,]   19   69
~                  > [20,]   20   70
  [20,]   21   71    [21,]   21   71
  [21,]   22   72    [22,]   22   72
@@ 42,6 @@         @@ 43,5 @@       
  [41,]   42   92    [42,]   42   92
  [42,]   43   93    [43,]   43   93
< [43,]   44   94  > [44,]  999   94
< [44,]   45   95  ~                
  [45,]   46   96    [45,]   46   96
  [46,]   47   97    [46,]   47   97
(In RStudio, this is shown in a colorful manner in the Viewer)

This also works for other types of objects, such as character vectors:

diffPrint(letters[1:3], c("a", "B", "c"))
< letters[1:3]     > c("a", "B", "..
@@ 1 @@            @@ 1 @@          
< [1] "a" "b" "c"  > [1] "a" "B" "c"

For more details, see the Introduction to diffobjj vignette, or the diffobj github rep.