This function generates the code for a model object, prints it to the console or writes it to a file.

render(
  model,
  filename = NULL,
  target_tool = "nonmem",
  tasks = tsk_estimation(),
  options = assemblerr_options()
)

Arguments

model

A model object

filename

Name of the model file to create or NULL

target_tool

Name of the target tool (currently only 'nonmem')

tasks

A task specification

options

List of options for model generation

Value

The model code as a character vector

Details

The generated code will be written to the file specified by filename= or printed to the console if the filename is set to NULL. Only 'nonmem' is currently supported as a target_tool= option. The tasks= argument allows the specification of model tasks and the options= argument customizes the generated code.

Task specification

Tasks are building blocks that allow to specify what a model should "do". Like other model building blocks, they can be combined using the + operator. For example, the following adds an estimation task and an xpose4 output task to the generated code:

   render(m, tasks = tsk_estimation() +
        tsk_output_xpose4())

The default argument (tasks=tsk_estimation()) adds an FOCE estimation task to the code.

Rendering options

The options= argument allows to modify the rendering process and, hence, the generated code. Options are provided as a list and the assemblerr_options() function helps to generate list with the proper formatting.

The following code block renders the model m with automatic mu-referencing for the model parameters

   render(m, options = assemblerr_options(prm.use_mu_referencing = TRUE))

Examples

m <- model() + input_variable("dose") + prm_log_normal("emax") + prm_log_normal("ed50") + obs_additive(eff~emax*dose/(ed50+dose)) # render to console render(m)
#> $PROBLEM #> $INPUT DOSE ID DV #> $DATA data.csv IGNORE=@ #> $PRED #> EMAX = THETA(1) * EXP(ETA(1)) #> ED50 = THETA(2) * EXP(ETA(2)) #> EFF = EMAX * DOSE/(ED50 + DOSE) #> Y = EFF + EPS(1) #> $ESTIMATION METHOD=COND MAXEVAL=999999 #> $THETA (0, 1, Inf) ; POP_EMAX #> $THETA (0, 1, Inf) ; POP_ED50 #> $OMEGA 0.1 ; IIV_EMAX #> $OMEGA 0.1 ; IIV_ED50 #> $SIGMA 1; RUV_ADD
# render to file if (FALSE) { setwd(tempdir()) render(m, "run1.mod") } # render to console with estimation & output task render(m, tasks = tsk_estimation() + tsk_output_xpose4())
#> $PROBLEM #> $INPUT DOSE ID DV #> $DATA data.csv IGNORE=@ #> $PRED #> EMAX = THETA(1) * EXP(ETA(1)) #> ED50 = THETA(2) * EXP(ETA(2)) #> EFF = EMAX * DOSE/(ED50 + DOSE) #> Y = EFF + EPS(1) #> $ESTIMATION METHOD=COND MAXEVAL=999999 #> $TABLE DV PRED RES WRES IPREDI IWRESI CWRES FILE=sdtab NOAPPEND NOPRINT #> $TABLE EMAX ED50 ETA(1) ETA(2) FILE=patab NOAPPEND NOPRINT #> $THETA (0, 1, Inf) ; POP_EMAX #> $THETA (0, 1, Inf) ; POP_ED50 #> $OMEGA 0.1 ; IIV_EMAX #> $OMEGA 0.1 ; IIV_ED50 #> $SIGMA 1; RUV_ADD