Prepare reference values selected by a model
Arguments
- model
An unresolved form model with named lookup bindings.
- configuration
Combined configuration from read_reference_configuration().
- offline
Use verified cached files only; defaults to FALSE.
- catalogues
Optional results from
get_reference_tables(), named by catalogue. Supply these to build lookups from tables already in memory.
Value
A list containing model (the resolved model) and references (named indexes with values, complete rows, lookup settings and provenance). The supplied model is unchanged.
Details
Table IDs and lookup columns come exclusively from the model's resolved bindings. Each required table is retrieved once per catalogue. Empty lookup values are excluded; duplicate rows and canonical spelling are retained. Catalogue aliases are grouped once by table and column. Each required lookup is indexed with only its own aliases and can be passed to reference_match_rows(). Alias file paths and checksums are recorded in provenance. Missing sources, tables or columns raise errors. No validation rules are run.
Examples
# Load the requested form model.
form_model_definition <- form.model::read_form_model("examples/survey/form.yaml", "form.model")
# Read the catalogue sources and lookup definitions.
reference_configuration <- read_reference_configuration(
system.file("examples", "survey", "references.yaml", package = "form.model"))
# Use a temporary cache for this example.
reference_cache_directory <- tempfile("model-references-")
# Assign the temporary cache to each catalogue source.
for (catalogue in names(reference_configuration$catalogues))
reference_configuration$catalogues[[catalogue]]$source$cache <- reference_cache_directory
# Prepare the reference tables required by the form model.
reference_preparation <- prepare_model_references(form_model_definition, reference_configuration)
# Display the returned values.
names(reference_preparation$references)
#> [1] "registries/contacts/email" "code_lists/stations/code"
#> [3] "code_lists/observers/code"
# Display the selected reference rows or values.
reference_preparation$references[["registries/contacts/email"]]$data
#> email name
#> 1 alice@example.org Alice Example
#> 2 bob@example.org Bob Example
#> 3 survey@example.org Survey Contact
# Remove the temporary files created by this example.
unlink(reference_cache_directory, recursive = TRUE)