renameByContents {NMdata}R Documentation

Rename columns matching properties of data contents

Description

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

Usage

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]
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]
pk <- renameByContents(data=pk,
                       fun.test = NMisNumeric,
                       fun.rename = function(x)paste0(x,"C"),
                       invert.test = TRUE)

[Package NMdata version 0.1.6 Index]