Skip to contents

Re-evaluates named statistics on data and compares each with the value the manifest recorded under that name: the check that the record is right, not only consistent with itself. Results recorded but not recomputed are listed as unchecked, and ok is FALSE while any are. This is rmoriebricklayer::mnfrcmp().

Usage

morie_capsule_compare(manifest, data, stats, tol = NULL)

Arguments

manifest

A manifest (from morie_capsule_manifest()) or the path to one written as JSON.

data

The data the statistics are computed from, passed unchanged to each function.

stats

A named list of functions of data, each returning one value; the names are the recorded result names.

tol

An absolute tolerance overriding each result's recorded one, or NULL to use the recorded one.

Value

A bricklayer_recompute list: ok, results (data frame of name, recorded, recomputed, delta, tol, status – "MATCH", "DIFFER", "NOT_RECORDED" or "ERROR" – and detail) and unchecked.

Details

Errors: manifest neither a manifest with results nor the path to one; stats not a non-empty named list of functions; tol not NULL or one non-negative number.

Examples

d <- data.frame(x = 1:10)
checks <- data.frame(name = c("n", "mean_x"), observed = c(10, 5.5),
                     expected = c(10, 5.5))
path <- tempfile(fileext = ".json")
suppressMessages(morie_capsule_manifest(list(project = "demo"), checks,
                                        path = path, env = FALSE))
stats <- list(n = nrow, mean_x = function(z) mean(z$x))
morie_capsule_compare(path, d, stats)$ok
#> [1] TRUE
morie_capsule_compare(path, data.frame(x = 1:11), stats)$results
#>     name recorded recomputed delta   tol status                        detail
#> 1      n     10.0         11   1.0 1e-04 DIFFER   |recorded - recomputed| = 1
#> 2 mean_x      5.5          6   0.5 1e-04 DIFFER |recorded - recomputed| = 0.5