For instance, lowercase all columns that Nonmem cannot interpret (as numeric).

renameByContents(data, fun.test, fun.rename, invert.test = FALSE, as.fun)

Arguments

data

data.frame in which to rename columns

fun.test

Function that returns TRUE for columns to be renamed.

fun.rename

Function that takes the existing column name and returns the new one.

invert.test

Rename those where FALSE is returned from fun.test.

as.fun

The default is to return data as a data.frame. Pass a function (say tibble::as_tibble) in as.fun to convert to something else. If data.tables are wanted, use as.fun="data.table". The default can be configured using NMdataConf.

Value

data with (some) new column names. Class as defined by as.fun.

Examples

pk <- readRDS(file=system.file("examples/data/xgxr2.rds",package="NMdata"))
pk[,trtact:=NULL]
#> Index: <FLAG>
#>         ROW    ID NOMTIME     TIME  EVID   CMT   AMT       DV  FLAG STUDY   BLQ
#>       <int> <int>   <num>    <num> <int> <int> <int>    <num> <num> <int> <int>
#>    1:     1    31     0.0  0.00000     1     1     3       NA     0     1     0
#>    2:     2    31     0.1  0.13381     0     2     0 0.050000    10     1     1
#>    3:     3    31     0.5  0.48619     0     2     0 0.050000    10     1     1
#>    4:     4    31     1.0  1.00637     0     2     0 0.050000    10     1     1
#>    5:     5    31     2.0  2.02464     0     2     0 0.050000    10     1     1
#>   ---                                                                          
#> 1498:  1498   180     4.0  4.14220     0     2     0 0.614680     0     1     0
#> 1499:  1499   180     8.0  8.16823     0     2     0 0.241030     0     1     0
#> 1500:  1500   180    12.0 12.15164     0     2     0 0.097516     0     1     0
#> 1501:  1501   180    18.0 18.04313     0     2     0 0.080055     0     1     0
#> 1502:  1502   180    23.9 23.87067     0     2     0 0.065688     0     1     0
#>       CYCLE  DOSE  PART PROFDAY PROFTIME WEIGHTB   eff0 EVENTU             NAME
#>       <int> <int> <int>   <int>    <num>   <num>  <num> <char>           <char>
#>    1:     1     3     1       1      0.0  87.031 56.461     mg           Dosing
#>    2:     1     3     1       1      0.1  87.031 56.461  ng/mL PK Concentration
#>    3:     1     3     1       1      0.5  87.031 56.461  ng/mL PK Concentration
#>    4:     1     3     1       1      1.0  87.031 56.461  ng/mL PK Concentration
#>    5:     1     3     1       1      2.0  87.031 56.461  ng/mL PK Concentration
#>   ---                                                                          
#> 1498:     1   300     1       1      4.0  98.103 57.835  ng/mL PK Concentration
#> 1499:     1   300     1       1      8.0  98.103 57.835  ng/mL PK Concentration
#> 1500:     1   300     1       1     12.0  98.103 57.835  ng/mL PK Concentration
#> 1501:     1   300     1       1     18.0  98.103 57.835  ng/mL PK Concentration
#> 1502:     1   300     1       1     23.9  98.103 57.835  ng/mL PK Concentration
#>       TIMEUNIT TRTACT         flag
#>         <char> <char>       <char>
#>    1:    Hours   3 mg       Dosing
#>    2:    Hours   3 mg   Below LLOQ
#>    3:    Hours   3 mg   Below LLOQ
#>    4:    Hours   3 mg   Below LLOQ
#>    5:    Hours   3 mg   Below LLOQ
#>   ---                             
#> 1498:    Hours 300 mg Analysis set
#> 1499:    Hours 300 mg Analysis set
#> 1500:    Hours 300 mg Analysis set
#> 1501:    Hours 300 mg Analysis set
#> 1502:    Hours 300 mg Analysis set
pk <- renameByContents(data=pk,
                       fun.test = NMisNumeric,
                       fun.rename = tolower,
                       invert.test = TRUE)
## Or append a "C" to the same column names
pk <- readRDS(file=system.file("examples/data/xgxr2.rds",package="NMdata"))
pk[,trtact:=NULL]
#> Index: <FLAG>
#>         ROW    ID NOMTIME     TIME  EVID   CMT   AMT       DV  FLAG STUDY   BLQ
#>       <int> <int>   <num>    <num> <int> <int> <int>    <num> <num> <int> <int>
#>    1:     1    31     0.0  0.00000     1     1     3       NA     0     1     0
#>    2:     2    31     0.1  0.13381     0     2     0 0.050000    10     1     1
#>    3:     3    31     0.5  0.48619     0     2     0 0.050000    10     1     1
#>    4:     4    31     1.0  1.00637     0     2     0 0.050000    10     1     1
#>    5:     5    31     2.0  2.02464     0     2     0 0.050000    10     1     1
#>   ---                                                                          
#> 1498:  1498   180     4.0  4.14220     0     2     0 0.614680     0     1     0
#> 1499:  1499   180     8.0  8.16823     0     2     0 0.241030     0     1     0
#> 1500:  1500   180    12.0 12.15164     0     2     0 0.097516     0     1     0
#> 1501:  1501   180    18.0 18.04313     0     2     0 0.080055     0     1     0
#> 1502:  1502   180    23.9 23.87067     0     2     0 0.065688     0     1     0
#>       CYCLE  DOSE  PART PROFDAY PROFTIME WEIGHTB   eff0 EVENTU             NAME
#>       <int> <int> <int>   <int>    <num>   <num>  <num> <char>           <char>
#>    1:     1     3     1       1      0.0  87.031 56.461     mg           Dosing
#>    2:     1     3     1       1      0.1  87.031 56.461  ng/mL PK Concentration
#>    3:     1     3     1       1      0.5  87.031 56.461  ng/mL PK Concentration
#>    4:     1     3     1       1      1.0  87.031 56.461  ng/mL PK Concentration
#>    5:     1     3     1       1      2.0  87.031 56.461  ng/mL PK Concentration
#>   ---                                                                          
#> 1498:     1   300     1       1      4.0  98.103 57.835  ng/mL PK Concentration
#> 1499:     1   300     1       1      8.0  98.103 57.835  ng/mL PK Concentration
#> 1500:     1   300     1       1     12.0  98.103 57.835  ng/mL PK Concentration
#> 1501:     1   300     1       1     18.0  98.103 57.835  ng/mL PK Concentration
#> 1502:     1   300     1       1     23.9  98.103 57.835  ng/mL PK Concentration
#>       TIMEUNIT TRTACT         flag
#>         <char> <char>       <char>
#>    1:    Hours   3 mg       Dosing
#>    2:    Hours   3 mg   Below LLOQ
#>    3:    Hours   3 mg   Below LLOQ
#>    4:    Hours   3 mg   Below LLOQ
#>    5:    Hours   3 mg   Below LLOQ
#>   ---                             
#> 1498:    Hours 300 mg Analysis set
#> 1499:    Hours 300 mg Analysis set
#> 1500:    Hours 300 mg Analysis set
#> 1501:    Hours 300 mg Analysis set
#> 1502:    Hours 300 mg Analysis set
pk <- renameByContents(data=pk,
                       fun.test = NMisNumeric,
                       fun.rename = function(x)paste0(x,"C"),
                       invert.test = TRUE)