Skip to contents

Build a shared lookup over reference rows

Usage

reference_index(data, column = NULL, matching = "exact", ignore_case = TRUE)

Arguments

data

Reference table, character vector or list of text values. Rows are retained in order.

column

Lookup column when data is a data frame; otherwise NULL.

matching

"exact" or "name" for optional normalized-name fallback.

ignore_case

Ignore case in keys, aliases and name fallback? Defaults to TRUE.

Value

A reference_index object retaining the original data, values and row indexes.

Details

Lookup keys are plain text. Values are never converted to text implicitly. Reference matching supports text fields only. Catalogue aliases attached to the selected column are applied automatically. Inspect index$aliases for that lookup's alias-to-canonical mappings. Exact matches take precedence over aliases, then name fallback. Duplicate rows remain separate matches. No catalogue-specific validity policy is applied: callers decide whether any match or exactly one match is required. Submitted and reference values are unchanged.

Examples

# Prepare species.
reference_species_table <- data.frame(code = c("001", "002"), label = c("First", "Second"))
# Prepare reference index.
reference_index <- reference_index(reference_species_table, "code")
# Prepare reference rows.
reference_rows <- reference_match_rows(reference_index, c("001", "unknown"))
# Display the selected reference rows or values.
reference_index$data[reference_rows[[1]], , drop = FALSE]
#>   code label
#> 1  001 First
# Display the number of matching rows for each submitted value.
lengths(reference_rows)
#> [1] 1 0