Diff, Patch and Merge for Data.frames

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.

version downloads Build Status AppVeyor Build Status

Working:

  • diff: diff_data
  • patch: patch_data
  • write/read diff: read_diff and write_diff
  • render to html: render_diff
  • merge two tables based on a same version: merge_data

TODO:

  • add htmlwidgets
  • implement extra parameters for diff_data: ids, ignore etc.
  • make column type changes explicit (is now internally available)
  • see if daff can be implemented in C++, using the Haxe C++ target of daff: this would remove the V8/jsonlite dependency

Install

Install from CRAN

install.packages('daff')

The latest version of daff can be installed with devtools

devtools::install_github("edwindj/daff")

Usage

diff_data

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 row
x[1,1] <- 10 # change a value
x$hello <- "world"  # add a column
x$Species <- NULL # remove a column
 
patch <- diff_data(y, x)
 
# write a patch to disk
write_diff(patch, "patch.csv")

render_diff(patch) will generate the following HTML page:

render_diff

patch_data

Patch a data.frame using a diff generated with diff_data.

# read a diff from disk
patch <- read_diff("patch.csv")
 
# apply patch
y_patched <- patch_data(y, patch)

merge_data

Merge two data.frames that have diverged from a common parent data.frame.

parent <- a <- b <- iris[1:3,]
a[1,1] <- 10
b[2,1] <- 11
# succesful merge
merge_data(parent, a, b)
 
parent <- a <- b <- iris[1:3,]
a[1,1] <- 10
b[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 conflict
which_conflicts(merged)

News

0.3.0

  • Lots of improvements thanks to @gwarnes-mdsol
  • 'render_diff' now defaults to 'pretty=TRUE'.
  • Use inline CSS instead of obsolete '' tag.
  • Improve Output Formatting and Add Support for Daff Flags
  • Update daff.js to version 1.3.25.

0.2.1

  • added summary for patch, thanks to @jsta, feature request #12

0.2.0

  • updated daff.js library to 1.3.16, thanks to @jeroenooms, solves issue #9

0.1.3

  • changed internal I() into JS() thanks to @jeroenooms

0.1.2

  • fixed issue #5 handling NA's, thanks to @eusebe
  • removed the R version dependency (is dependent on V8)

0.1.1

  • initial version

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("daff")

0.3.5 by Edwin de Jonge, a month ago


http://github.com/edwindj/daff


Browse source code at https://github.com/cran/daff


Authors: Paul Fitzpatrick [aut] (JavaScript original , http://paulfitz.github.io/daff/) , Edwin de Jonge [aut, cre] (R wrapper , , Gregory R. Warnes [aut]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports V8, jsonlite, utils

Suggests testthat


See at CRAN