In R, find whether two files differ

前端 未结 5 1088
春和景丽
春和景丽 2021-01-04 07:50

I would like a pure R way to test whether two arbitrary files are different. So, the equivalent to diff -q in Unix, but should work on Windows and without exter

5条回答
  •  盖世英雄少女心
    2021-01-04 08:30

    Example solution: (Using all.equals utility from: https://stat.ethz.ch/R-manual/R-devel/library/base/html/all.equal.html)

    filenameForA <- "my_file_A.txt"
    filenameForB <- "my_file_B.txt"
    all.equal(readLines(filenameForA), readLines(filenameForB))
    

    Note, that

    readLines(filename)
    

    reads all the lines from given file specified by filename, then all.equal can figure out if the files differ or not.

    Make sure to read the documentation from above to understand fully. I've to admit, that if the files are very large, this might not be the best option.

提交回复
热议问题