Reputation: 52318
install.packages("diffobj")
library(diffobj)
first_string <- "It's
a
nice
day"
second_string <- "it's
a
nice
day"
produces
How would we produce the same output but with actual new lines displayed on screen (rather than \n
)
Note: diffObj()
has a pager="off"
option which will simply display the HTML (text) output rather than rendering it in the viewer pane in RStudio. It may be a useful start.
Upvotes: 2
Views: 70
Reputation: 1986
You can use the diffFile method ...
# Load package
library(diffobj)
# Define strings
first_string <- ("It's
a
nice
day")
second_string <- ("it's
a
nice
day")
# Write them out to temporary locations.
first_string_output <- file.path(tempdir(), "first_string_output")
second_string_output <- file.path(tempdir(), "second_string_output")
write.table(first_string, file = first_string_output, col.names = F, row.names = F, quote = F)
write.table(second_string, file = second_string_output, col.names = F, row.names = F, quote = F)
# DiffFile them
diffFile(first_string_output, second_string_output)
Upvotes: 2