|
8 | 8 | #' @family internal |
9 | 9 | #' @importFrom assertthat assert_that |
10 | 10 | #' @importFrom git2r hash |
| 11 | +#' @importFrom utils file_test |
11 | 12 | datahash <- function(file) { |
12 | | - chunk_size <- 1e4 |
13 | | - hashes <- character(chunk_size + 1) |
14 | | - i <- 0 |
15 | | - rawdata <- scan( |
16 | | - file = file, what = character(), nmax = -1, sep = "\n", quote = "", |
17 | | - skip = i * chunk_size, nlines = chunk_size, na.strings = "", |
18 | | - flush = FALSE, fill = FALSE, strip.white = FALSE, quiet = TRUE, |
19 | | - blank.lines.skip = FALSE, comment.char = "", allowEscapes = FALSE, |
20 | | - encoding = "UTF-8", skipNul = FALSE |
21 | | - ) |
22 | | - while (length(rawdata)) { |
23 | | - hashes[1 + i %% chunk_size] <- hash(paste(hash(rawdata), collapse = "\n")) |
24 | | - i <- i + 1 |
25 | | - if (i %% chunk_size == 0) { |
26 | | - hashes[chunk_size + 1] <- hash(paste(hashes, collapse = "")) # nocov |
27 | | - } |
| 13 | + if (file_test("-f", file)) { |
| 14 | + chunk_size <- 1e4 |
| 15 | + hashes <- character(chunk_size + 1) |
| 16 | + i <- 0 |
28 | 17 | rawdata <- scan( |
29 | 18 | file = file, what = character(), nmax = -1, sep = "\n", quote = "", |
30 | 19 | skip = i * chunk_size, nlines = chunk_size, na.strings = "", |
31 | 20 | flush = FALSE, fill = FALSE, strip.white = FALSE, quiet = TRUE, |
32 | 21 | blank.lines.skip = FALSE, comment.char = "", allowEscapes = FALSE, |
33 | 22 | encoding = "UTF-8", skipNul = FALSE |
34 | 23 | ) |
| 24 | + while (length(rawdata)) { |
| 25 | + hashes[1 + i %% chunk_size] <- hash(paste(hash(rawdata), collapse = "\n")) |
| 26 | + i <- i + 1 |
| 27 | + if (i %% chunk_size == 0) { |
| 28 | + hashes[chunk_size + 1] <- hash(paste(hashes, collapse = "")) # nocov |
| 29 | + } |
| 30 | + rawdata <- scan( |
| 31 | + file = file, what = character(), nmax = -1, sep = "\n", quote = "", |
| 32 | + skip = i * chunk_size, nlines = chunk_size, na.strings = "", |
| 33 | + flush = FALSE, fill = FALSE, strip.white = FALSE, quiet = TRUE, |
| 34 | + blank.lines.skip = FALSE, comment.char = "", allowEscapes = FALSE, |
| 35 | + encoding = "UTF-8", skipNul = FALSE |
| 36 | + ) |
| 37 | + } |
| 38 | + } else { |
| 39 | + hashes <- sapply( |
| 40 | + list.files( |
| 41 | + file, pattern = "(index|[[:xdigit:]]{20}\\.tsv$)", full.names = TRUE |
| 42 | + ), |
| 43 | + datahash |
| 44 | + ) |
35 | 45 | } |
36 | 46 | hash(paste(hashes, collapse = "")) |
37 | 47 | } |
|
0 commit comments