write_results() adds a manifest to a results object and writes the
object to path with qs2::qs_save(). It writes no file when the object
with its manifest gives a FAIL in check_results().
Usage
write_results(
x,
path,
version,
source_md5,
data_files = NULL,
packages = session_packages(),
manifest_extra = list()
)Arguments
- x
The results object: a list that is not a data.frame and has no element
manifest.- path
The path of the results file.
- version
The version label of the run, for example
"v01".- source_md5
A named character vector of the md5 of each source file of the run. Each name is the path of a file.
- data_files
NULL, or a data.frame with the columnsfile,sizeandmtime, or those andmd5. WithNULL, the manifest has no elementdata_files.- packages
A named character vector of package versions. The default gives the version of each package that this R session loaded.
- manifest_extra
A named list of more manifest fields, for example
n_rows_data. Each name is not empty, comes once, and is not a core name.
Details
The manifest is a list with these elements, in this order:
writer:list(package = "writeit", version = <the installed version of writeit>).r_version:R.version.string.packages.run_date: the date of the run, as"YYYY-MM-DD".version.source_md5.data_files, only when it is notNULL.The elements of
manifest_extra, in their order.
The first 7 names are the core names. manifest_extra MUST NOT use one.
An empty manifest_extra adds no element.
write_results() stops before it writes when one of these is true:
xis not a list, or is a data.frame.xholds an elementmanifest.manifest_extrais not a list with a unique, non-empty name for each element.manifest_extrauses a core name.check_results()gives a FAIL onxwith its manifest. The message gives the rule and the detail of each FAIL.
The function writes to a temporary file in the folder of path and then
renames that file to path. When the rename fails, it removes the
temporary file and stops.
See also
Other results:
check_results(),
writeit_messages()
Examples
path <- tempfile(fileext = ".qs2")
x <- list(estimates = data.frame(term = "x", estimate = 1.2))
write_results(
x,
path,
version = "v01",
source_md5 = c(run.R = "fedcba9876543210fedcba9876543210"),
manifest_extra = list(n_rows_data = 100L)
)
names(qs2::qs_read(path)$manifest)
#> [1] "writer" "r_version" "packages" "run_date" "version"
#> [6] "source_md5" "n_rows_data"
unlink(path)