r8check() holds every row of a table against rules, or against the columns and
the rules of a type, and reports what it finds. It refuses nothing: data that were
read from a file are checked as they are, before they are converted or cleaned.
r8validate() requires, and raises an error.
Arguments
- x
A value of a table, or a data frame. Any other object for a type of other values, which is checked as a whole.
- against
A
rule(), a list of rules, or a type: an R8 type object, or a field type such astype_table().- limit
Integer: The problems listed for each rule.
- n_threads
Optional Integer [1, Inf): The threads that the work in Rust may use;
NULLtakesgetOption("r8.n_threads"), whose default is half the logical cores, at most 2 whereR CMD checklimits the cores, and at mostOMP_THREAD_LIMIT. A result is the same for any number of threads.
Value
A value of the struct R8::Report, with the fields type, the type that the
table was held against or NULL, rows, rules, and problems.
The report
The report is an R8 value of two tables. rules has a row for each rule, or each
declared column: the rows that were checked, those that failed, those where a rule
has no answer since a cell is missing, and those where it is an error, such as a
division by zero. The counts are exact. problems has a row for each rule and row
that failed, with the columns, the values found in them, and the explanation, for at
most limit rows of each rule. A rule that names a column that the table does not
have is not checked: its checked is 0, and problems says why.
Rules
A rule (rule()) reads the cells of a row by the names of the columns. A rule
that reads whole columns only, such as rule(mean(age) > 18), is checked once. A
name in the list is the rule's ID, as in a declaration. A list of rules is saved
as any R object, and is checked against any table with the columns it names.
Examples
visits <- data.frame(
age = c(40, 152, 61),
dbp = c(80, 85, 130),
sbp = c(120, NA, 118)
)
report <- r8check(
visits,
list(pressures = rule(dbp < sbp), age = rule(age <= 130))
)
report#> 0 of 2 rules hold on 3 rows
#> pressures 1 row fails, 1 row without an answer (row 3)
#> age 1 row fails (row 2)
#> $problems lists 2 problemsreport$problems#> <R8::ReportProblems table> 2 rows ⨉ 6 columns
#> rule row columns found code
#> character integer character character character
#> 1 pressures 3 dbp, sbp dbp = 130, sbp = 118 rule_violation
#> 2 age 2 age age = 152 rule_violation
#> 1 column not shown: message#> <R8::ReportProblems table> 1 row ⨉ 6 columns
#> rule row columns found code message
#> character integer character character character character
#> 1 age 2 age age = 152 rule_violation age <= 130