assign_meta_data {sdtmval} | R Documentation |
Assign meta data to columns in a SDTM table based on specification file
Description
Trims the length of each text and date variable to the length specified in
the spec and then assigns the attributes "label"
and "width"
to each
column.
Usage
assign_meta_data(
tbl,
spec,
datatype_col = "Data Type",
var_col = "Variable",
length_col = "Length",
label_col = "Label"
)
Arguments
tbl |
a data frame containing a SDTM table |
spec |
a data frame with the columns |
datatype_col |
a string, the column in |
var_col |
a string, the column in |
length_col |
a string, the column in |
label_col |
a string, the column in |
Value
a modified copy of tbl
with the meta data per specification
See Also
get_data_spec()
, get_key_vars()
, get_codelist()
Examples
work_dir <- system.file("extdata", package = "sdtmval")
spec <- get_data_spec(domain = "XX",
dir = work_dir,
filename = "spec.xlsx")
after_meta_data <- assign_meta_data(sdtmval::xx_no_meta_data, spec = spec)
labels <- colnames(after_meta_data) |>
purrr::map(~ attr(after_meta_data[[.]], "label")) |>
unlist()
lengths <- colnames(after_meta_data) |>
purrr::map(~ attr(after_meta_data[[.]], "width")) |>
unlist()
data.frame(
column = colnames(after_meta_data),
labels = labels,
lengths = lengths
)