validate_consistency_tbl {eHDPrep}R Documentation

Validate internal consistency table

Description

Runs a series of checks on a table of internal consistency rules (see Consistency Table Requirements) in preparation for identify_inconsistency.

Usage

validate_consistency_tbl(data, consis_tbl)

Arguments

data

data frame which will be checked for internal consistency

consis_tbl

data frame or tibble containing information on internal consistency rules (see "Consistency Table Requirements" section)

Value

Error message or successful validation message is printed. The dataset is returned invisibly.

Consistency Table Requirements

Table must have exactly five character columns. The columns should be ordered according to the list below which describes the values of each column:

  1. First column name of data values that will be subject to consistency checking. String. Required.

  2. Second column name of data values that will be subject to consistency checking. String. Required.

  3. Logical test to compare columns one and two. One of: ">",">=", "<","<=","==", "!=". String. Optional if columns 4 and 5 have non-NA values.

  4. Either a single character string or a colon-separated range of numbers which should only appear in column A. Optional if column 3 has a non-NA value.

  5. Either a single character string or a colon-separated range of numbers which should only appear in column B given the value/range specified in column 4. Optional if column 3 has a non-NA value.

Each row should detail one test to make. Therefore, either column 3 or columns 4 and 5 must contain non-NA values.

See Also

Other internal consistency functions: identify_inconsistency()

Examples

require(tibble)
# example with synthetic dataset on number of bean counters
# there is a lot going on in the function so a simple dataset aids this example
#
# creating `data`:
beans <- tibble::tibble(red_beans = 1:15,
blue_beans = 1:15,
total_beans = 1:15*2,
red_bean_summary = c(rep("few_beans",9), rep("many_beans",6)))
#
# creating `consis_tbl`
bean_rules <- tibble::tribble(~varA, ~varB, ~lgl_test, ~varA_boundaries, ~varB_boundaries,
"red_beans", "blue_beans", "==", NA, NA,
"red_beans", "total_beans", "<=", NA,NA,
"red_beans", "red_bean_summary", NA, "1:9", "few_beans",
"red_beans", "red_bean_summary", NA, "10:15", "many_beans")

validate_consistency_tbl(beans, bean_rules)

[Package eHDPrep version 1.3.3 Index]