check.unique: Check unique constraints

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

View source: R/check.unique.r

Description

Check for violation of a unique constraint

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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 March 4, 2020, 4:50 p.m.