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
The function comparedf() is used to compare two dataframes in R.
R scripts are that solution. A script is simply a text file containing a set of commands and comments. The script can be saved and used later to re-execute the saved commands. The script can also be edited so you can execute a modified version of the commands.
An R script is simply a text file containing (almost) the same commands that you would enter on the command line of R. ( almost) refers to the fact that if you are using sink() to send the output to a file, you will have to enclose some commands in print() to get the same output as on the command line.
To run an R command, put the cursor on the line of the command and then click the Run button at the top of the file window. Or just press CTRL-Enter.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With