Skip to contents

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 columns file, size and mtime, or those and md5. With NULL, the manifest has no element data_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.

Value

path, invisibly.

Details

The manifest is a list with these elements, in this order:

  1. writer: list(package = "writeit", version = <the installed version of writeit>).

  2. r_version: R.version.string.

  3. packages.

  4. run_date: the date of the run, as "YYYY-MM-DD".

  5. version.

  6. source_md5.

  7. data_files, only when it is not NULL.

  8. 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:

  • x is not a list, or is a data.frame.

  • x holds an element manifest.

  • manifest_extra is not a list with a unique, non-empty name for each element.

  • manifest_extra uses a core name.

  • check_results() gives a FAIL on x with 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

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)