A short hash that changes whenever the content changes: of R objects
(texts, rule lists, dictionaries), or of files (files = TRUE). Store it
with a derived output (write_stamp()) or in a table column, to know
which outputs must be recomputed after an input changed.
Arguments
- x
An R object, or a character vector of file paths when
files = TRUE.- files
Logical. Hash the content of the files named by
xrather thanxitself.- algo
Character. Hash algorithm passed to
digest::digest().
Details
For R objects, the hash is computed on the serialised object, so it also
changes with attributes and types (1L and 1 differ). For text, hash
the character vector itself; for files, the hash of each file is combined
in the order given.
See also
Other versions:
write_stamp()
Examples
content_hash(c("rule one", "rule two"))
#> [1] "7647bc2226a96cbd91182270813d67c4"
f <- tempfile()
writeLines("some text", f)
content_hash(f, files = TRUE)
#> [1] "da006516ab6e08eccf8298f114c3916e"