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 |
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.
create_diff(oldFile = NULL, newFile = NULL)
create_diff(oldFile = NULL, newFile = NULL)
oldFile |
old |
newFile |
new |
create_diff("foo\nbar", "foo\nbaz")
create_diff("foo\nbar", "foo\nbaz")
Shows diff based on the diff2html (MIT) js library by Rodrigo Fernandes. Most of the option descriptions are from their github page.
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" )
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" )
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 |
height |
for |
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. |
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)
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)
Use diffr2Output()
to create a UI element, and renderDiffr2()
to render the diffr2 widget.
diffr2Output(outputId, width = "100%", height = "400px") renderDiffr2(expr, env = parent.frame(), quoted = FALSE)
diffr2Output(outputId, width = "100%", height = "400px") renderDiffr2(expr, env = parent.frame(), quoted = FALSE)
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 |
quoted |
Is |
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.