Derived outputs (cleaned texts, matches, LLM caches, dictionaries applied)
depend on a method, its version and its inputs. A stamp is a small text
file saved next to an output (<output>.stamp) that records them:
write_stamp()saves the stamp of an output;read_stamp()reads it;check_stamp()compares it with the current method, version and inputs, and refuses (by default) an output built under another version, so that a stale cache is never used by mistake.
Usage
write_stamp(path, method, version, inputs = NULL, notes = NULL)
read_stamp(path)
check_stamp(
path,
method,
version,
inputs = NULL,
action = c("abort", "warn", "none")
)Arguments
- path
Character. Path of the output file.
- method
Character. Name of the method (e.g.
"generic_cleaning").- version
Character. Version of the method (e.g.
"v3"). Bump it whenever a rule changes.- inputs
NULL, or a fingerprint of the inputs fromcontent_hash().- notes
Character or
NULL. Free text saved with the stamp.- action
Character. What
check_stamp()does when the stamp does not match:"abort","warn", or"none"(only returnFALSE).
Value
write_stamp(): the path of the stamp, invisibly. read_stamp():
a named list, or NULL when there is no stamp. check_stamp(): TRUE
when the stamp matches, FALSE otherwise (invisibly).
Details
The stamp also records the date, the R version and the version of
coRpusdb. It is written in Debian control format (one field: value per
line), readable by eye and by any language.
See also
Other versions:
content_hash()
Examples
out <- tempfile(fileext = ".rds")
saveRDS(data.frame(doc_id = "a:1", text = "cleaned"), out)
write_stamp(out, method = "generic_cleaning", version = "v3")
read_stamp(out)
#> $method
#> [1] "generic_cleaning"
#>
#> $version
#> [1] "v3"
#>
#> $created_at
#> [1] "2026-11-08 17:50:33 CET"
#>
#> $r_version
#> [1] "4.6.2"
#>
#> $coRpusdb_version
#> [1] "0.2.0"
#>
check_stamp(out, method = "generic_cleaning", version = "v3")
check_stamp(out, method = "generic_cleaning", version = "v4", action = "warn")
#> Warning: /tmp/RtmpKqItGK/file79980262156cf.rds was not built by the current method.
#> ✖ version v3, expected v4