stevec
stevec

Reputation: 52318

Display new lines (not new line characters) when using diffObj in R?

install.packages("diffobj")
library(diffobj)


first_string <- "It's
a
nice
day"

second_string <- "it's
a
nice
day"

produces

enter image description here

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

Answers (1)

Khaynes
Khaynes

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

Related Questions