File: helper-files.R

package info (click to toggle)
r-cran-bslib 0.9.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,412 kB
  • sloc: javascript: 13,349; makefile: 33; sh: 23
file content (30 lines) | stat: -rw-r--r-- 699 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Returns TRUE if two files have identical contents
identical_files <- function(a, b) {
  content_a <- readBin(a, "raw", file.size(a))
  content_b <- readBin(b, "raw", file.size(b))
  identical(content_a, content_b)
}

# Returns TRUE if two directories have identical contents, recursively.
identical_dirs <- function(a, b) {
  if (!all(dir.exists(c(a, b)))) {
    return(FALSE)
  }
  files_a <- sort(dir(a, recursive = TRUE))
  files_b <- sort(dir(b, recursive = TRUE))
  if (!identical(files_a, files_b)) {
    return(FALSE)
  }

  for (file in files_a) {
    res <- identical_files(
      file.path(a, file),
      file.path(b, file)
    )
    if (!res) {
      return(FALSE)
    }
  }

  TRUE
}