daff: Diff, Patch and Merge for Data.frames

データフレームの差分や結合をおこなう

> library(daff)

バージョン: 0.1.4


関数名 概略
daff Data diff, patch and merge for R
diff_data Do a data diff
differs_from differs from,
merge_data Merge two tables based on a parent version
patch_data patch data
render_diff Render a data diff to html
which_conflicts return which rows of a merged 'data.frame' contain conflicts
write_diff Write or read a diff to or from a file

diff_data

> x <- iris
> x[1,1] <- 10
> diff_data(x, iris)
@@,Sepal.Length,Sepal.Width,Petal.Length,Petal.Width,Species
->,10->5.1,3.5,1.4,0.2,setosa
,4.9,3,1.4,0.2,setosa
...,...,...,...,...,...

merge_data

> parent <- a <- b <- iris[1:3,]
> a[1,1] <- 10
> b[2,1] <- 11
> # succesful merge
> merge_data(parent, a, b)
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1         10.0         3.5          1.4         0.2  setosa
2         11.0         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa

patch_data

> x <- iris
> #change a value
> x[1,1] <- 1000
> patch <- diff_data(iris, x)
> print(patch)
@@,Sepal.Length,Sepal.Width,Petal.Length,Petal.Width,Species
->,5.1->1000,3.5,1.4,0.2,setosa
,4.9,3,1.4,0.2,setosa
...,...,...,...,...,...
> # apply patch
> iris_patched <- patch_data(iris, patch)
> iris_patched[1,1] == 1000
[1] TRUE

render_diff

> 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)
> render_diff(patch)

write_diff