Examples for 'diffobj::ses'


Shortest Edit Script

Aliases: ses ses_dat

Keywords:

### ** Examples

a <- letters[1:6]
b <- c('b', 'CC', 'DD', 'd', 'f')
ses(a, b)
[1] "1d0"   "3c2,3" "5d4"  
(dat <- ses_dat(a, b))
"ses_dat" object (Match: 3, Delete: 3, Insert: 2):
                    
D: a   c         e  
M:   b         d   f
I:       CC DD      
## use `ses_dat` output to construct a minimal diff
## color with ANSI CSI SGR
diff <- dat[['val']]
del <- dat[['op']] == 'Delete'
ins <- dat[['op']] == 'Insert'
if(any(del))
  diff[del] <- paste0("\033[33m- ", diff[del], "\033[m")
if(any(ins))
  diff[ins] <- paste0("\033[34m+ ", diff[ins], "\033[m")
if(any(!ins & !del))
  diff[!ins & !del] <- paste0("  ", diff[!ins & !del])
writeLines(diff)
- a
  b
- c
+ CC
+ DD
  d
- e
  f
## We can recover `a` and `b` from the data
identical(subset(dat, op != 'Insert', val)[[1]], a)
[1] TRUE
identical(subset(dat, op != 'Delete', val)[[1]], b)
[1] TRUE

[Package diffobj version 0.3.5 Index]