Add a lookup table to the database together with its metadata. Note that it is not possible to overwrite an existing lookup table.
Arguments
- table
The lookup table to add, should be coercible to a
data.frame- metadata
The lookup metadata, as specified by
lookup_metadata().
Details
Lookup tables are indexed by their code_type and version, specified in
lookup_metadata(). This index needs to be unique and is used to identify
the lookup table in the database. If a lookup table with the same
code_type and version already exists, the function will emit a warning
and return FALSE (invisibly) without any effect. Use a different version
to add a new version of the lookup table for the given code_type.
See also
lookup_metadata() for the specification of the metadata.
Examples
# Using the example ontology data included in codeminer
lookup_table <- example_ontology$lookup_tables$capital_letters_v3
lookup_table
#> # A tibble: 9 × 2
#> code description
#> <chr> <chr>
#> 1 A ALPHA
#> 2 B BRAVO
#> 3 C CHARLIE
#> 4 D DELTA
#> 5 E ECHO
#> 6 alpha_code Alpha Attribute
#> 7 beta_code Beta Attribute
#> 8 gamma_code Gamma Attribute
#> 9 delta_code Delta Attribute
# Using a temporary database
Sys.setenv(CODEMINER_DB_PATH = tempfile())
build_database()
#> Creating new database at /tmp/RtmpRK6Py7/file1bd3662cb224
add_lookup_table(
lookup_table,
lookup_metadata("capital_letters", lookup_version = "v3")
)
#> ✔ Lookup table capital_letters_v3 added successfully.