Package 'diffr2'

Title: Display text file differences
Description: An R interface to the 'diff2html' JavaScript library (see <https://github.com/rtfpessoa/diff2html> for information). Based on the diffr package by John Muschelli. Includes copies of javascript libraries jsdiff and diff2html.
Authors: Jan Marvin Garbuszus [aut, cre]
Maintainer: Jan Marvin Garbuszus <[email protected]>
License: MIT + file LICENSE
Version: 1.4
Built: 2024-11-08 05:59:09 UTC
Source: https://github.com/JanMarvin/diffr2

Help Index


create a diff as character string

Description

creates a diff of two text files. Based on jsdiff (BSD) javascript library by Kevin Decker. If character vectors are supplied, a diff will be created from them as well.

Usage

create_diff(oldFile = NULL, newFile = NULL)

Arguments

oldFile

old

newFile

new

Examples

create_diff("foo\nbar", "foo\nbaz")

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)

Wrapper functions for using diffr2 in shiny

Description

Use diffr2Output() to create a UI element, and renderDiffr2() to render the diffr2 widget.

Usage

diffr2Output(outputId, width = "100%", height = "400px")

renderDiffr2(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from

width, height

the width and height of the diffr2 widget

expr

An expression that generates an HTML widget (or a promise of an HTML widget).

env

The environment in which to evaluate expr.

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.

Details

When calling renderDiffr2() make sure that divname matches the selected shiny output name. The div name is used to attach the diff2html output. Otherwise the canvas will be blank.