check.link: Check foreign key constraints

View source: R/check.link.r

check.linkR Documentation

Check foreign key constraints

Description

Check for violation of a foreign key constraint

Usage

check.link(
  child.tbl,
  child.col,
  parent.tbl,
  parent.col,
  na.ok = FALSE,
  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).

na.ok

Logical. Allow NA values in the child column without the respective complement in the parent column?

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


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