check.key: Check (primary) key constraints

View source: R/check.key.r

check.keyR Documentation

Check (primary) key constraints

Description

Check for violation of a (primary) key constraint

Usage

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


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 Feb. 9, 2023, 12:34 a.m.