Add label attribute to data set columns

ys_add_labels(data, spec, fun = label.ycol)

Arguments

data

a data.frame to label

spec

yspec object for data

fun

the function to use for forming label

Details

An error is generated if the names of data are not identical to names of spec.

If the user passes fun to generate a custom label, the function must take a single argument, the column ycol object, and must return the label for that column as a character vector of length one.

Examples

spec <- ys_help$spec()

data <- ys_help$data()

data <- ys_add_labels(data,spec)

sapply(data,attr,"label")
#>                               C                             NUM 
#>             "comment character"                 "record number" 
#>                              ID                            SUBJ 
#>            "subject identifier"            "subject identifier" 
#>                            TIME                             SEQ 
#>         "time after first dose"                     "data type" 
#>                             CMT                            EVID 
#>            "compartment number"                      "event ID" 
#>                             AMT                              DV 
#>                   "dose amount"            "dependent variable" 
#>                             AGE                              WT 
#>                           "age"                        "weight" 
#>                            CRCL                             ALB 
#>          "creatinine clearance"                 "serum albumin" 
#>                             BMI                             AAG 
#>               "body mass index"     "alpha-1-acid glycoprotein" 
#>                             SCR                             AST 
#>              "serum creatinine"    "aspartate aminotransferase" 
#>                             ALT                              HT 
#>      "alanine aminotransferase"                        "Height" 
#>                              CP                            TAFD 
#>              "Child-Pugh score"         "time after first dose" 
#>                             TAD                            LDOS 
#>               "time after dose"              "last dose amount" 
#>                             MDV                             BLQ 
#>          "missing DV indicator" "below limit of quantification" 
#>                           PHASE                           STUDY 
#>         "study phase indicator"                  "study number" 
#>                              RF 
#>          "renal function stage" 

str(data[,1:5])
#> 'data.frame':	4360 obs. of  5 variables:
#>  $ C   : logi  NA NA NA NA NA NA ...
#>   ..- attr(*, "label")= chr "comment character"
#>  $ NUM : int  1 2 3 4 5 6 7 8 9 10 ...
#>   ..- attr(*, "label")= chr "record number"
#>  $ ID  : int  1 1 1 1 1 1 1 1 1 1 ...
#>   ..- attr(*, "label")= chr "subject identifier"
#>  $ SUBJ: int  1 1 1 1 1 1 1 1 1 1 ...
#>   ..- attr(*, "label")= chr "subject identifier"
#>  $ TIME: num  0 0.61 1.15 1.73 2.15 3.19 4.21 5.09 6.22 8.09 ...
#>   ..- attr(*, "label")= chr "time after first dose"