This function takes a dataset and applies user-specified column mappings
provided through a Shiny input object. It renames columns based
on the selected mappings, handles special cases such as ADOSEDUR,
updates units for key variables, applies labels,
and removes detected duplicate concentration records.
apply_mapping(
dataset,
mapping,
desired_order,
silent = TRUE,
req_mappings = c("USUBJID", "AFRLT", "NFRLT", "ARRLT", "NRRLT", "PCSPEC", "ROUTE",
"AVAL", "STUDYID", "ATPTREF", "AVALU", "RRLTU", "DOSEU", "PARAM")
)A transformed data frame with:
Renamed columns according to user mappings
Created columns for mapped non-existent variables (e.g., mg/L in AVALU)
Created columns for unmapped required variables (e.g., ADOSEDUR)
Ordered columns as specified
Labels applied to columns (via apply_labels())
Concentration duplicates removed based on key identifiers:
AFRLT, STUDYID, PCSPEC, DOSETRT, USUBJID, and PARAM
A data frame containing the raw data to be transformed.
A named list of column mappings.
A character vector specifying the desired column order in the output dataset.
Boolean, whether to print message with applied mapping.
Defaults to TRUE.
A character vector indicating the names of the mapping object that must always be populated
Validates that all required columns are mapped and no duplicates exist.
If ADOSEDUR is not mapped, it is assigned a value of 0.
Removes concentration data duplicates using all columns except ARRLT, NRRLT,
and ATPTREF.