Last active
January 31, 2020 01:52
-
-
Save joelnitta/d9d59f4af9869d2609fc012b979ca3a4 to your computer and use it in GitHub Desktop.
Compare hashes of identically named files across two project versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compare hashes of identically named files across two project versions, | |
# e.g. if the project was run again with different versions of dependencies. | |
# >>> Assumes files are uniquely named within a project <<< | |
# (replace vector of paths appropriately) | |
library(digest) | |
library(tidyverse) | |
files_to_check_01 <- list.files( | |
# Check all of the files in these directories | |
c("/project_v1/dir1", | |
"/project_v1/dir2"), | |
full.names = TRUE, recursive = TRUE) %>% | |
set_names(fs::path_file(.)) %>% | |
map(read_lines) | |
hashes_01 <- map_chr(files_to_check_01, digest::digest) %>% | |
tibble(hash_01 = ., file = names(.)) | |
files_to_check_02 <- list.files( | |
c("/project_v2/dir1", | |
"/project_v2/dir2"), | |
full.names = TRUE, recursive = TRUE) %>% | |
set_names(fs::path_file(.)) %>% | |
map(read_lines) | |
hashes_02 <- map_chr(files_to_check_02, digest::digest) %>% | |
tibble(hash_02 = ., file = names(.)) | |
left_join(hashes_01, hashes_02) %>% | |
select(file, hash_01, hash_02) %>% | |
filter(hash_01 != hash_02) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment