Learn R Programming

R.AlphA.Home (version 2.0.2)

show_diff: Compare two texts or files with diffobj

Description

This function compares two inputs (files or text strings) and displays the differences using the diffobj package with syntax highlighting.

Usage

show_diff(input1, input2)

Value

A diffobj object containing the visual comparison of the two inputs.

Arguments

input1

A character string. Either a file path or text content to compare.

input2

A character string. Either a file path or text content to compare.

Examples

Run this code
# Compare two text strings
show_diff("Hello\nWorld", "Hello\nR World")

# Compare two files
if (FALSE) {
show_diff("file1.txt", "file2.txt")
}

# Mix file and text
if (FALSE) {
show_diff("file.txt", "New content\nWith changes")
}

Run the code above in your browser using DataLab