add_lookup: Add attribute lookup relations

View source: R/shared_class_functions.r

add_lookupR Documentation

Add attribute lookup relations

Description

Create single-attribute relations for each of a given set of attributes. If the original object also contains references, then the new lookup relations are connected to other appearances of their attribute by chains of references.

Usage

add_lookup(x, as, ...)

Arguments

x

a relational schema object, such as a relation_schema or database_schema object, or a relational data object, such as a relation or database object.

as

a character vector of elements from attrs_order(x), indicating which attributes to create lookup tables for.

...

further arguments pass on to methods.

Details

Whether an attribute in as gets a new key relation depends on the relations already present. An existing relation is considered to be a lookup if the following hold:

  • The attribute is a simple key for the relation;

  • If x is a relation data object, then the relation contains all given values for that attribute.

If the original object includes references, then references are added to connected each attribute's appearances to its lookup. If several relations could be a lookup for the attribute, then add_lookup fails due to the desired result being ambiguous.

Value

an object of the same class as x.

Examples

db <- autodb(ChickWeight)
db
add_lookup(db, "Time")
add_lookup(db, "Chick") # Chick is already a key, so this does nothing
# data objects round numeric and complex values before checking given values
add_lookup(db, "weight", digits = 3)
## Not run: add_lookup(c(db, db), "Chick") # fails: two lookup candidates
# two lookups without references is fine
rels <- subrelations(db)
add_lookup(c(rels, rels), "Chick")

autodb documentation built on Aug. 4, 2026, 1:08 a.m.