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 "Variable" which has a value for each column in tbl, "Data Type" which specifies data types by column, "Length" which specifies the character limit for each column, and "Label" which specifies the label for each column

datatype_col

a string, the column in spec that contains the data types (which should include the values "text" and "date"); default is "Data Type"

var_col

a string, the column in spec that contains the domain variable names

length_col

a string, the column in spec that contains the character count limits for each variable

label_col

a string, the column in spec that contains the labels for each variable

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
)


[Package sdtmval version 0.4.1 Index]