| Title: | Display Differences Between Two Files using Codediff Library | 
| Version: | 0.3.0 | 
| 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. | 
| Depends: | R (≥ 3.0) | 
| Imports: | htmlwidgets | 
| License: | GPL-2 | 
| RoxygenNote: | 7.3.2 | 
| Suggests: | shiny | 
| BugReports: | https://github.com/muschellij2/diffr/issues | 
| NeedsCompilation: | no | 
| Packaged: | 2025-04-01 13:51:14 UTC; johnmuschelli | 
| Author: | John Muschelli [aut, cre] | 
| Maintainer: | John Muschelli <muschellij2@gmail.com> | 
| Repository: | CRAN | 
| Date/Publication: | 2025-04-01 15:10:02 UTC | 
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  | 
| height | passed to  | 
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
 | 
| expr | An expression that generates a  | 
| env | The environment in which to evaluate  | 
| quoted | Is  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)