check.key: Check (primary) key constraints

Description Usage Arguments Value Note Author(s) See Also Examples

View source: R/check.key.r

Description

Check for violation of a (primary) key constraint

Usage

1
check.key(x, cols, silent = FALSE)

Arguments

x

Data frame representing a table of a data base.

cols

Names of the colum(s) of x to which the constraint applies (vector of type character).

silent

Logical. If FALSE, details on constraint violations are shown using print.

Value

TRUE if the check was passed successfully and FALSE otherwise.

Note

The function performs a check for duplicates (using check.unique) and missing values (using check.notnull). If cols has length > 1, this is interpreted as a composite key (and not as a set of individual key columns). See the examples.

Author(s)

David Kneis david.kneis@tu-dresden.de

See Also

There are more functions to check constraints, namely check.notnull, check.unique, and check.link. See also the example for db.read.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
data(temperature)
print(temperature)

# Should succeed
check.key(temperature, c("day", "city"))

# Duplicates not allowed in keys
temperature[2, "day"] <- 1
print(temperature)
check.key(temperature, c("day", "city"))
# Missing values not allowed in keys
temperature[2, "day"] <- NA
check.key(temperature, c("day", "city"))

dkneis/tabular documentation built on March 4, 2020, 4:50 p.m.