Diff, patch and merge for data frames. Document changes in data sets and use them to apply patches. Changes to data can be made visible by using render_diff. The V8 package is used to wrap the 'daff.js' JavaScript library which is included in the package.
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 http://dataprotocols.org/tabular-diff-format.
Working:
diff_data
patch_data
read_diff
and write_diff
render_diff
merge_data
TODO:
diff_data
: ids
, ignore
etc.Install from CRAN
install.packages('daff')
The latest version of daff
can be installed with devtools
devtools::install_github("edwindj/daff")
Calculate the difference between a reference and a changed data.frame
library(daff)y <- iris[1:3,]x <- y x <- head(x,2) # remove a rowx[1,1] <- 10 # change a valuex$hello <- "world" # add a columnx$Species <- NULL # remove a column patch <- diff_data(y, x) # write a patch to diskwrite_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 diskpatch <- read_diff("patch.csv") # apply patchy_patched <- patch_data(y, patch)
Merge two data.frame
s that have diverged from a common parent data.frame
.
parent <- a <- b <- iris[1:3,]a[1,1] <- 10b[2,1] <- 11# succesful mergemerge_data(parent, a, b) parent <- a <- b <- iris[1:3,]a[1,1] <- 10b[1,1] <- 11# conflicting merge (both a and b change same cell)merged <- merge_data(parent, a, b)merged #note the conflict #find out which rows contain a conflictwhich_conflicts(merged)
0.3.0
0.2.1
0.2.0
0.1.3
0.1.2
0.1.1