Skip to contents

Parses NONMEM statements and attempts to apply them to a data frame in order to create a response variable

Usage

applyPredCode(
  df,
  pred,
  respCol = getEctdColName("Response"),
  report = TRUE,
  keepCols = respCol,
  verbose = getEctdVerbose()
)

parsePredCode(model, respCol = getEctdColName("Response"))

Arguments

df

(Required) Data frame to which parsed NONMEM statements are to be applied

pred

Character vector of NONMEM statements

respCol

Response column name ( iven by getEctdColName by default)

report

Logical: should a textual report be produced?

keepCols

Character vector of column names to retain in the return dataset

verbose

Logical: Should verbose logging be used? ( given by getEctdVerbose by default)

model

File containing analysis code (for R or SAS) or an R function for analysis (R only) parsePredCode(c( "X = 1", "IF (X.EQ.1.OR.Y.GT.0) STUD = 1", "NEWVAR = THETA(1) + EXP(ETA(2))**LOG(EPS(1))" ))

Value

A dataset with new columns added

Details

The applyPredCode function calls the parsePredCode function in order to convert the NONMEM statements to executable R statements. The applyPredCode function then iteratively "tries" to apply these statements to the data ("df"), producing a textual report of the process if "report" is set to TRUE. The "keepCols" columns from the updated dataset are then returned

Author

Mike K Smith mstoolkit@googlemail.com

Examples

applyPredCode(
df = data.frame(X = 1:5, TH1 = rep(1, 5),
 TH2 = rep(2, 5), ETA1 = rep(3, 5), EPS1 = rep(4, 5)), 
pred = parsePredCode(c("TEST = 1","XCOPY = X","TH2COPY = THETA(2)",
"Y = XCOPY + LOG(THETA(1)) + THETA(2)**2 + ETA(1) + SQRT(EPS(1)) + 1")),
             respCol ="RESP",
             report = FALSE, 
             keepCols = c("TEST", "XCOPY", "TH2COPY", "RESP"))
#>   X TH1 TH2 ETA1 EPS1 TEST XCOPY TH2COPY RESP
#> 1 1   1   2    3    4    1     1       2   11
#> 2 2   1   2    3    4    1     2       2   12
#> 3 3   1   2    3    4    1     3       2   13
#> 4 4   1   2    3    4    1     4       2   14
#> 5 5   1   2    3    4    1     5       2   15