daff is an R package that can find difference in values between
data.frames
, store this difference, render it and apply
this difference to patch a data.frame
. It can also merge
two versions of a data.frame
having a common parent. It
wraps the daff.js library
using the V8 package.
The diff format is described in https://paulfitz.github.io/daff-doc/spec.html.
Functions:
diff_data
patch_data
read_diff
and
write_diff
render_diff
merge_data
You can install the development version of daff from GitHub with:
# install.packages("devtools")
::install_github("edwindj/daff") devtools
Calculate the difference between a reference and a changed
data.frame
library(daff)
<- iris[1:3,]
y <- y
x
<- head(x,2) # remove a row
x 1,1] <- 10 # change a value
x[$hello <- "world" # add a column
x$Species <- NULL # remove a column
x
<- diff_data(y, x)
patch
# write a patch to disk
write_diff(patch, "patch.csv")
render_diff(patch)
will generate the following HTML
page:
Patch a data.frame
using a diff generated with
diff_data
.
# read a diff from disk
<- read_diff("patch.csv")
patch
# apply patch
<- patch_data(y, patch) y_patched
Merge two data.frame
s that have diverged from a common
parent data.frame
.
<- a <- b <- iris[1:3,]
parent 1,1] <- 10
a[2,1] <- 11
b[# succesful merge
merge_data(parent, a, b)
<- a <- b <- iris[1:3,]
parent 1,1] <- 10
a[1,1] <- 11
b[# conflicting merge (both a and b change same cell)
<- merge_data(parent, a, b)
merged #note the conflict
merged
#find out which rows contain a conflict
which_conflicts(merged)