'Are my R scripts identical?
I think this must be a duplicate but I can't seem to find the answer on stack. Is there a way to compare two R scripts in the same wd to see if they are identical?
Something like:
a <- source("script1.R")
b <- source("script2.R")
identical(a, b)
I don't just mean the functions in each script but all the other things like comments etc.
Thanks
Solution 1:[1]
I made three files (each ending with a newline):
iscript.R
script
iscript2.R
script
niscript.R
not script
Using the md5sum function from tools, I got the hash of :
tools::md5sum(c("iscript.R", "iscript2.R", "niscript.R"))
iscript.R iscript2.R niscript.R
"95d26f42dccb2ec048a30261e0e2863f" "95d26f42dccb2ec048a30261e0e2863f" "d4bef1be4af7baedd2d69e649feb01d1"
The files with the same hash are identical.
Solution 2:[2]
In case you need to compare two or three scripts side-by-side.
You can use open source software like WinMerge to get a one-to-one visual comparison of the actual text in a script. You will need to save the scripts text files to use as inputs
More info can be found here: https://winmerge.org/downloads/?lang=en
Another alternative is to use SublimeText: Comparing the contents of two files in Sublime Text
Both tools allow you to print diff file to PDF.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sebastian-c |
| Solution 2 |
