check_constraints-methods: Methods for function 'check_constraints'

Description Arguments Value Methods Examples

Description

Methods which check one object against another object containing constraints which must be met. Most commonly a data.frame is checked against constraints in a TableChecks object.

Arguments

object

The object to be checked.

checks

The object containing the constraints.

Value

TRUE if all constraints are met. If a constraint is failed, a character vector describing the problems.

Methods

signature(object = "ANY", checks = "ColumnChecks")
signature(object = "data.frame", checks = "TableChecks")
signature(object = "CheckedFrame", checks = "missing")

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# create a TableChecks object
# Require a numeric column foo and a factor column bar#
# Also require foo to be positive
positive <- function(x) x > 0
columns <- ColumnCheckList(foo = ColumnChecks(classtype = "numeric",
                             constraints = FunctionList(postive=positive)),
                           bar = ColumnChecks(classtype = "factor"))
# Require that the data.frame can contain ONLY foo and bar
checks <- TableChecks(columns = columns, exclusive = TRUE)
# this data frame is valid
check_constraints(data.frame(foo = 1:26, bar = letters),
                  checks)
# these are invalid
check_constraints(data.frame(foo = -(1:26), bar=letters), checks)
check_constraints(data.frame(foo = 1:26, bar=1:26), checks)
check_constraints(data.frame(foo = 1:26, bar=letters, baz=letters),
                  checks)

jrnold/r-checker documentation built on May 20, 2019, 1:04 a.m.