Skip to contents

Give a file input an immutable content identity

Usage

shared_file(path, id = NULL)

Arguments

path

Character vector of input file paths. Ordering and names matter.

id

One immutable identifier per path, such as an already established SHA-256 or immutable object version. Supplying IDs avoids reading the files. If omitted, SHA-256 is computed from each regular file's contents.

Value

A path-like character vector with class tarshare_file. It can be passed to ordinary file-reading functions. Its identity uses id, names, and ordering, rather than physical paths.

Details

Supplying id asserts that the identifier describes the bytes used by the computation. The caller owns verification when localizing or registering those files. The cache does not repeat that verification. Explicit IDs may also describe immutable directories; automatic hashing accepts regular files.

Relocation is safe only when the command depends on contents rather than pathnames. Include any meaningful filename, sample label, or path-dependent tool setting separately in the computation or its context.

Examples

path <- tempfile()
writeLines("1,2,3", path)
input <- shared_file(path)
readLines(input)
#> [1] "1,2,3"