check.link: Check foreign key constraints

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

View source: R/check.link.r

Description

Check for violation of a foreign key constraint

Usage

1
check.link(child.tbl, child.col, parent.tbl, parent.col, silent = FALSE)

Arguments

child.tbl

Data frame representing the table on the 'many' side of an 'one-to-many' relation. See notes.

child.col

Name of a column from child.tbl providing the link to the other table (character string).

parent.tbl

Data frame representing the table on the 'one' side of an 'one-to-many' relation. See notes.

parent.col

Name of a column from parent.tbl providing the link to the other table (character string).

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 is made to verify that two tables having a one-to-many relation (https://en.wikipedia.org/wiki/One-to-many_(data_model)) can successfully be joined on the specified columns.

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.key. See also the example for db.read.

Examples

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

# Should succeed
check.link(people, "id_country", countries, "id")

# Example of an orphaned child record
check.link(people, "id_country", countries[1:2,], "id")

# Example of ambiguity
countries2 <- rbind(countries, data.frame(id=3, country="India"))
check.link(people, "id_country", countries2, "id")

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