Map variables to certain attributes, e.g. by default their labels.
prep_map_labels( x, item_level ="item_level", to = LABEL, from = VAR_NAMES, ifnotfound, warn_ambiguous =FALSE, meta_data_v2, meta_data = item_level
)
Arguments
x: character variable names, character vector, see parameter from
item_level: data.frame metadata data frame, if, as a dataquieR
developer, you do not have item-level-metadata , you should use util_map_labels instead to avoid consistency checks on for item-level meta_data.
to: character variable attribute to map to
from: character variable identifier to map from
ifnotfound: list A list of values to be used if the item is not found: it will be coerced to a list if necessary.
warn_ambiguous: logical print a warning if mapping variables from from to to produces ambiguous identifiers.
meta_data_v2: character path to workbook like metadata file, see prep_load_workbook_like_file for details. ALL LOADED DATAFRAMES WILL BE PURGED , using prep_purge_data_frame_cache, if you specify meta_data_v2.
meta_data: data.frame old name for item_level
Returns
a character vector with:
mapped values
Details
This function basically calls colnames(study_data) <- meta_data$LABEL, ensuring correct merging/joining of study data columns to the corresponding metadata rows, even if the orders differ. If a variable/study_data-column name is not found in meta_data[[from]] (default from = VAR_NAMES), either stop is called or, if ifnotfound has been assigned a value, that value is returned. See mget, which is internally used by this function.
The function not only maps to the LABEL column, but to can be any metadata variable attribute, so the function can also be used, to get, e.g. all HARD_LIMITS from the metadata.