Prepare catalogue tables and explicit correspondences for mappings
Source:R/mapping.R
prepare_mapping_references.RdPrepare catalogue tables and explicit correspondences for mappings
Usage
prepare_mapping_references(
mapping,
configurations,
targets = NULL,
offline = FALSE,
catalogues = NULL
)Arguments
- mapping
A configuration from read_mapping_configuration().
- configurations
Named list of reference configurations from read_reference_configuration(), keyed by the mapping's configuration names.
- targets
Target table IDs to prepare; NULL selects every configured target.
- offline
Use verified reference caches only. Correspondence CSVs are local files.
- catalogues
Optional results from
get_reference_tables(), grouped first by configuration name and then by catalogue name. These supply tables already in memory.
Value
A mapping_references object retaining the selected alternatives, shared reference indexes, correspondence tables and provenance.
Details
Retrieves each required table once per configuration and catalogue. Source rows are required only for property-based correspondences. File-based and unchanged-input mappings check source declarations but load target data only. Different lookups share table retrieval; repeated identical lookups share indexes.
Checks actual lookup and property columns, CSV headers and nonempty text values. Identical CSV pairs are deduplicated; conflicting targets remain candidates. Preparation does not require every source value to have a correspondence.
Examples
local({
directory <- system.file("examples", "survey", package = "form.model")
mapping <- read_mapping_configuration(file.path(directory, "mapping.yaml"))
source <- read_reference_configuration(file.path(directory, "references-source.yaml"))
target <- read_reference_configuration(file.path(directory, "references.yaml"))
configurations <- list(source = source, target = target)
on.exit({
for (configuration in configurations) {
for (catalogue in configuration$catalogues) unlink(catalogue$source$cache, recursive = TRUE)
}
})
prepared <- prepare_mapping_references(mapping, configurations)
map_reference_values(prepared, "stations", c("station-north", "station-unmapped"))[, 1:4]
})
#> source_value target_value status stage
#> 1 station-north 001 resolved target
#> 2 station-unmapped <NA> no_match correspondence