Skip to contents

Creates a named lookup list keyed by the values of key_var in anchor_data. Each entry is a named character vector of the corresponding row's columns. When multiple rows share the same key value (e.g. duplicate USUBJID), the first row wins.

This is used internally by validate() when anchor_datasets is supplied, making subject-level context available across datasets without injecting columns.

Usage

build_anchor_index(anchor_data, key_var, call = rlang::caller_env())

Arguments

anchor_data

A data frame (e.g. DM).

key_var

Character scalar. The column name to use as the lookup key (e.g. "USUBJID").

call

Caller environment for error reporting.

Value

A named list where each name is a unique key value and each element is a named character vector of that row's column values.

Examples

dm <- data.frame(
  USUBJID = c("S1-001", "S1-002"),
  AGE = c(45L, 62L),
  SEX = c("M", "F"),
  stringsAsFactors = FALSE
)
idx <- build_anchor_index(dm, "USUBJID")
idx[["S1-001"]][["AGE"]]  # "45"
#> [1] "45"