The st_write function is intended to be a wrapper of several
other functions in different packages that save data disk. Yet, it goes
several steps beyond that. First it creates the stamps (e.g., hashes) as
part of the attributes of the object and saves it in a different file for
easy access. Also, it may create vintage files of the object to keep track
of changes. The philosophy of this package is increase speed in processes
that work with many files, avoiding the need to load files to check whether
the data has changed or not. Since disk space is cheap and time is not,
stamp may be redundant in the files it saves.
Usage
st_write(
x,
file,
ext = fs::path_ext(file),
st_dir = NULL,
st_name = NULL,
save_stamp = TRUE,
complete_stamp = getOption("stamp.completestamp"),
recurse = FALSE,
force = FALSE,
algo = getOption("stamp.digest.algo"),
save_vintage = getOption("stamp.vintage"),
vintage_dir = NULL,
verbose = getOption("stamp.verbose"),
...
)Arguments
- x
R object to write to disk as per limitations of
fileformat.- file
character: File or connection to write to
- ext
character: format or extension of file. Default is
fs::path_ext(file)- st_dir
character: Directory to store stamp files. By default it is a subdirectory at the same level of
file.- st_name
character: name of stamp in file. All stamp files are prefixed with value in option "stamp.stamp_prefix", which by default is "st_". You don't need to add the prefix.
- save_stamp
logical: Whether to save a stamp in a separate file. Default is TRUE. It doesn't make a lot of sense to use
st_write()whensave_stamp = FALSE, as saving data along with the stamp is the main functionality ofst_write().- complete_stamp
logical: Whether to add a complete report of data.frame to stamp file. You need the
skimrpackage. Ifskimris not in namespace, limited but lighter report will be added.- recurse
logical: is
TRUEif directory infiledoes not it will be created. Default is FALSE- force
logical: replace file in disk even if has hasn't changed
- algo
character: Algorithm to be used in
digest::digest(). Default is "sha1"- save_vintage
logical: Whether to save vintage versions
x. DefaultTRUE- vintage_dir
character: Directory to save vintages of
x. By default it is a subdirectory at the same level offile- verbose
logical: whether to display additional information. This could be changed in option
"stamp.verbose". Default isTRUE- ...
Arguments passed on to
stamp_getserializeA logical variable indicating whether the object should be serialized using
serialize(in ASCII form). Setting this toFALSEallows to compare the digest output of given character strings to known control output. It also allows the use of raw vectors such as the output of non-ASCII serialization.lengthNumber of characters to process. By default, when
lengthis set toInf, the whole string or file is processed.skipNumber of input bytes to skip before calculating the digest. Negative values are invalid and currently treated as zero. Special value
"auto"will cause serialization header to be skipped ifserializeis set toTRUE(the serialization header contains the R version number thus skipping it allows the comparison of hashes across platforms and some R versions).asciiThis flag is passed to the
serializefunction ifserializeis set toTRUE, determining whether the hash is computed on the ASCII or binary representation.rawA logical variable with a default value of FALSE, implying
digestreturns digest output as ASCII hex values. Set to TRUE to returndigestoutput in raw (binary) form. Note that this option is supported by most but not all of the implemented hashing algorithmsseedan integer to seed the random number generator. This is only used in the
xxhash32,xxhash64andmurmur32functions and can be used to generate additional hashes for the same input if desired.errormodeA character value denoting a choice for the behaviour in the case of error: ‘stop’ aborts (and is the default value), ‘warn’ emits a warning and returns
NULLand ‘silent’ suppresses the error and returns an empty string.
Examples
if (FALSE) {
tfile <- fs::file_temp(ext = "qs")
st_write(df, tfile)
}