check.unique: Check unique constraints

View source: R/check.unique.r

check.uniqueR Documentation

Check unique constraints

Description

Check for violation of a unique constraint

Usage

check.unique(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). See notes.

silent

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

Value

TRUE if the check was passed successfully and FALSE otherwise.

Note

If cols has length > 1, uniqueness is checked for the combination of columns rather than for each column individually. 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.key, and check.link. See also the example for db.read.

Examples


data(temperature)
print(temperature)

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

# Example of duplicates
temperature[2, "day"] <- 1
print(temperature)
check.unique(temperature, c("day", "city"))

dkneis/tabular documentation built on Feb. 9, 2023, 12:34 a.m.