Skip to contents

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

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
)
#>      column                              labels lengths
#> 1   STUDYID                    Study Identifier     200
#> 2   USUBJID           Unique Subject Identifier     200
#> 3     XXSEQ                     Sequence Number       8
#> 4  XXTESTCD                  XX Test Short Name       8
#> 5    XXTEST                        XX Test Name      40
#> 6   XXORRES Result or Finding in Original Units     200
#> 7    XXBLFL                       Baseline Flag       1
#> 8     VISIT                          Visit Name     200
#> 9     EPOCH                               Epoch     200
#> 10    XXDTC           Date/Time of Measurements      19
#> 11     XXDY                     Study Day of XX       8