Skip to contents

check_results() checks a results object against the contract of the results file. It reports each of its 6 rules as PASS, FAIL or SKIP, and it does not print or stop.

Usage

check_results(x, home = NULL, messages = writeit_messages())

Arguments

x

The results object.

home

NULL, or the folder that holds the files that the manifest names. The rule results_current compares each md5 in the manifest with the file at file.path(home, <name>). With NULL, it gives SKIP.

messages

The texts that name a function in a detail, a named list as writeit_messages() gives. The details use its element writer.

Value

A data.frame with 6 rows, one for each rule, and the columns rule, status and detail. status is "PASS", "FAIL" or "SKIP".

Details

A list with no element manifest is a legacy result: something wrote it before the manifest. On a legacy result, the rules manifest_data, manifest_source and results_current give SKIP. The rule element_names gives FAIL on a fault in the names and SKIP otherwise. SKIP means that the rule could not compare. It is never a PASS.

The 6 rules, in the order of the rows:

  • element_names: x is a list and not a data.frame. Each element has a name. Each name is syntactic, so make.names() does not change it, and no name is there twice. The element manifest is there at most once.

  • allowed_objects: each element at each depth is a data.frame, an atomic vector of any class, NULL, or a list of any class. The walk goes into each list, each column of a data.frame and each attribute, and it writes the path of an attribute as attr(x$a, "terms"). It skips the attributes that R and data.table set: names, dim, dimnames, row.names, class, levels, tzone, units, comment, sorted, index and .internal.selfref.

    The rule fails these objects, and the detail names the path, the class and a fix of each:

    • a function, an environment, a call, a formula, a name and an external pointer.

    • an S4 object and an R6 object.

    • a fitted model of the class lm, glm, gam, merMod, brmsfit, coxph or lavaan.

  • no_row_per_person: no element at any depth has one value for each row of the data. The walk skips manifest and exclusions. exclusions is a table with one row for each step, so k steps and k people would fail it. The rule reads the row counts in the optional manifest fields n_rows_data, n_rows_before_exclusions, n_rows_after_exclusions and n_rows_lists. For each count n of 2 or more, it fails these objects:

    • a data.frame with n rows.

    • an atomic vector of length n.

    • a matrix or an array with a dimension n.

    When there is no count of 2 or more, it gives PASS and says that it checked nothing.

  • manifest_data: when manifest$data_files is there, it MUST be a data.frame with the columns file, size and mtime, or those and md5. Its values MUST obey these rules:

    • each file is a name that is not empty and comes once.

    • each size is a number of 0 or more.

    • each mtime is a number.

    • each md5 is 32 lower-case hex digits or NA.

    Without data_files, the rule gives PASS.

  • manifest_source: manifest$source_md5 is a named character vector of one or more md5 values, each 32 lower-case hex digits. Each name is there once and is not empty.

  • results_current: each md5 of source_md5, and each md5 of data_files that is not NA, is the md5 of its file in home. The rule gives FAIL and names each file that differs. It gives SKIP when home is NULL, when a file is not in home, or when the manifest records no md5. It gives PASS only when it compared each md5.

See also

Examples

x <- list(
  manifest = list(
    version = "v01",
    source_md5 = c(run.R = "fedcba9876543210fedcba9876543210"),
    data_files = data.frame(file = "main/d.csv", size = 120, mtime = 1.8e9),
    n_rows_data = 100L
  ),
  estimates = data.frame(term = "x", estimate = 1.2),
  p_interaction = 0.04
)
check_results(x)
#>                rule status
#> 1     element_names   PASS
#> 2   allowed_objects   PASS
#> 3 no_row_per_person   PASS
#> 4     manifest_data   PASS
#> 5   manifest_source   PASS
#> 6   results_current   SKIP
#>                                                                                detail
#> 1                       manifest, and each other element with a unique syntactic name
#> 2             each element is a data.frame, an atomic vector, NULL or a list of these
#> 3 no data.frame has 100 rows, and no vector or matrix has 100 values in one dimension
#> 4              manifest$data_files names each data file once, with its size and mtime
#> 5                       the manifest has source_md5, with the md5 of each source file
#> 6                                                 home is NULL, so no file to compare

# A legacy result, written before the manifest.
check_results(list(estimates = data.frame(term = "x", estimate = 1.2)))
#>                rule status
#> 1     element_names   SKIP
#> 2   allowed_objects   PASS
#> 3 no_row_per_person   PASS
#> 4     manifest_data   SKIP
#> 5   manifest_source   SKIP
#> 6   results_current   SKIP
#>                                                                                                                      detail
#> 1 x has no manifest, so it was written before the manifest. Write it again with writeit::write_results() to check this rule
#> 2                                                   each element is a data.frame, an atomic vector, NULL or a list of these
#> 3                                                                                    n_rows_data is NA, so nothing to check
#> 4 x has no manifest, so it was written before the manifest. Write it again with writeit::write_results() to check this rule
#> 5 x has no manifest, so it was written before the manifest. Write it again with writeit::write_results() to check this rule
#> 6 x has no manifest, so it was written before the manifest. Write it again with writeit::write_results() to check this rule