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 |
Takes the diff of 2 files and shows comparisons
diffr( file1, file2, contextSize = 3, minJumpSize = 10, wordWrap = TRUE, before = file1, after = file2, width = NULL, height = NULL )
diffr( file1, file2, contextSize = 3, minJumpSize = 10, wordWrap = TRUE, before = file1, after = file2, width = NULL, height = NULL )
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 |
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")
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")
Use diffrOutput
to create a UI element, and renderDiffr
to render the diff.
diffrOutput(outputId, width = "100%", height = "400px") renderDiffr(expr, env = parent.frame(), quoted = FALSE)
diffrOutput(outputId, width = "100%", height = "400px") renderDiffr(expr, env = parent.frame(), quoted = FALSE)
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 |
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)
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)