Package 'diffr'

Title: Display Differences Between Two Files using Codediff Library
Description: An R interface to the 'codediff' JavaScript library (a copy of which is included in the package, see <https://github.com/danvk/codediff.js> for information). Allows for visualization of the difference between 2 files, usually text files or R scripts, in a browser.
Authors: John Muschelli [aut, cre]
Maintainer: John Muschelli <[email protected]>
License: GPL-2
Version: 0.2
Built: 2024-10-25 04:46:54 UTC
Source: https://github.com/muschellij2/diffr

Help Index


Diff 2 files side by side

Description

Takes the diff of 2 files and shows comparisons

Usage

diffr(
  file1,
  file2,
  contextSize = 3,
  minJumpSize = 10,
  wordWrap = TRUE,
  before = file1,
  after = file2,
  width = NULL,
  height = NULL
)

Arguments

file1

First file to take diff (usually original file)

file2

First file to take diff (usually updated file)

contextSize

Minimum number of lines of context to show around each diff hunk. (default: 3).

minJumpSize

Minimum number of equal lines to collapse into a “Show N more lines” link. (default: 10)

wordWrap

By default, code will go all the way to the right margin of the diff. If there are 60 characters of space, character 61 will wrap to the next line, even mid-word. To wrap at word boundaries instead, set this option.

before

Text to display on file1

after

Text to display on file2

width

passed to createWidget

height

passed to createWidget

Examples

library(diffr)
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)
diffr(file1, file2, before = "f1", after = "f2")

Wrapper functions for using diffr in shiny

Description

Use diffrOutput to create a UI element, and renderDiffr to render the diff.

Usage

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

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

Arguments

outputId

Output variable to read from

width, height

The width and height of the diff (see shinyWidgetOutput)

expr

An expression that generates a diffr object

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.

Widget output function for use in Shiny

Examples

library(diffr)
library(shiny)
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)

ui <- fluidPage(
  h1("A diffr demo"),
  checkboxInput("wordWrap", "Word Wrap",
     value = TRUE),
   diffrOutput("exdiff")
)

server <- function(input, output, session) {
  output$exdiff <- renderDiffr({
    diffr(file1, file2, wordWrap = input$wordWrap,
    before = "f1", after = "f2")
  })
}

shinyApp(ui, server)