diffr2: View text file differences

View source: R/diffr2.R

diffr2R Documentation

View text file differences

Description

Shows diff based on the diff2html (MIT) js library by Rodrigo Fernandes. Most of the option descriptions are from their github page.

Usage

diffr2(
  oldFile = NULL,
  newFile = NULL,
  diff = NULL,
  width = NULL,
  height = NULL,
  synchronisedScroll = TRUE,
  stickyFileHeaders = TRUE,
  highlight = TRUE,
  fileListToggle = TRUE,
  fileListStartVisible = FALSE,
  fileContentToggle = TRUE,
  outputFormat = "line-by-line",
  drawFileList = TRUE,
  diffMaxChanges = NA,
  diffMaxLineLength = NA,
  matching = "none",
  matchWordsThreshold = 0.25,
  maxLineLengthHighlight = 10000,
  diffStyle = "word",
  renderNothingWhenEmpty = FALSE,
  matchingMaxComparisons = 2500,
  maxLineSizeInBlockForComparison = 200,
  divname = "htmlwidget_container",
  colorScheme = "auto"
)

Arguments

oldFile

Your reference file (the old file). Either a path or a character.

newFile

Your comparison file (the new file). Either a path or a character.

diff

Alternatively you can provide your diff file. Either a path or a character. If provided, it overrides oldFile & newFile diff.

width

for createWidget

height

for createWidget

synchronisedScroll

scroll both panes in side-by-side mode: TRUE or FALSE, default is TRUE

stickyFileHeaders

make file headers sticky: TRUE or FALSE, default is TRUE

highlight

syntax highlight the code on the diff: TRUE or FALSE, default is TRUE

fileListToggle

allow the file summary list to be toggled: TRUE or FALSE, default is TRUE

fileListStartVisible

choose if the file summary list starts visible: TRUE or FALSE, default is FALSE

fileContentToggle

allow each file contents to be toggled: TRUE or FALSE, default is TRUE

outputFormat

the format of the output data: 'line-by-line' or 'side-by-side', default is 'line-by-line'

drawFileList

show a file list before the diff: TRUE or FALSE, default is TRUE

diffMaxChanges

number of changed lines after which a file diff is deemed as too big and not displayed, default is undefined

diffMaxLineLength

number of characters in a diff line after which a file diff is deemed as too big and not displayed, default is undefined

matching

matching level: 'lines' for matching lines, 'words' for matching lines and words or 'none', default is none

matchWordsThreshold

similarity threshold for word matching, default is 0.25

maxLineLengthHighlight

only perform diff changes highlight if lines are smaller than this, default is 10000

diffStyle

show differences level in each line: 'word' or 'char', default is 'word'

renderNothingWhenEmpty

render nothing if the diff shows no change in its comparison: TRUE or FALSE, default is FALSE

matchingMaxComparisons

perform at most this much comparisons for line matching a block of changes, default is 2500

maxLineSizeInBlockForComparison

maximum number os characters of the bigger line in a block to apply comparison, default is 200

divname

the default is ''htmlwidget_container'', for shiny it must match the 'output$divname'

colorScheme

color scheme to use for the diff, default is 'auto'. Possible values are light, dark, and auto which will use the browser's preferred color scheme.

Examples

library(diffr2)
file1 = tempfile()
writeLines("hello, world!\n", con = file1)
file2 = tempfile()
writeLines(paste0(
"hello world?\nI don't get it\n",
paste0(sample(letters, 65, replace = TRUE), collapse = "")), con = file2)
diffr2(file1, file2)

JanMarvin/diffr2 documentation built on Dec. 27, 2024, 12:12 p.m.