Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show difference between files or objects

Tags:

r

diff

Is there a way in R to compare objects and return something useful like where the differences are? I need to compare files, but am willing to read them in to data.frames. This might just be handled better from the command line, but I would like to encapsulate my testing into one R script. My next attempt will be to use ddply to send each line to a compare() function and return the line numbers of the "FALSE" lines, but that only works until you have one insertion or deletion, then everything else becomes "FALSE".

Thanks.

EDIT: the files contain a combination of numeric and character data.

like image 357
James Avatar asked Oct 18 '11 18:10

James


People also ask

How can I find the difference between two folders?

If you double-click on a folder, it will expand to reveal its contents. If you double-click on a file it will open a side by side comparison and will highlight the differences, if any, between the two files. Double-clicking a file will open both copies in a side by side view and will highlight any differences.


Video Answer


1 Answers

I know it has been a while, but if someone else stumbles on this...

If you are only looking to view the differences, and not use them in code, see the package diffr.

install.packages("diffr")
library(diffr)
diffr("file1.txt", "file2.txt", contextSize = 0, minJumpSize = 500)

It shows the total contents of both files side by side with differences highlighted in the RStudio Viewer.

like image 55
Mike Avatar answered Oct 21 '22 05:10

Mike