Importing NONMEM into rxode2

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(rxode2)
setRxThreads(1L)
library(data.table)
setDTthreads(1L)

The goal of nonmem2rx is to convert a NONMEM control stream to rxode2 for easy clinical trial simulation in R.

Here is a quick example of a conversion:

library(nonmem2rx)

# First we need the location of the nonmem control stream Since we are running an example, we will use one of the built-in examples in `nonmem2rx`
ctlFile <- system.file("mods/cpt/runODE032.ctl", package="nonmem2rx")
# You can use a control stream or other file. With the development
# version of `babelmixr2`, you can simply point to the listing file

mod <- nonmem2rx(ctlFile, lst=".res", save=FALSE, determineError=FALSE)
mod

Setting up nonmem2rx for your model

Some common options that you may want to change when importing NONMEM control stream are:

You probably also want to change the name of parameters and compartments. The easiest way to name the parameters whatever you want is to pre-specify the names. For example:

mod <- nonmem2rx(system.file("mods/cpt/runODE032.ctl", package="nonmem2rx"), lst=".res", save=FALSE,
                 thetaNames=c("lcl", "lvc", "lq", "lvp", "prop.sd"),
                 etaNames=c("eta.cl", "eta.vc", "eta.q","eta.vp"),
                 cmtNames = c("central", "perip"))

mod

This checks the parameter names to make sure they are the same length as the input names, if they are not, the model will skip parameter renaming and keep the default translation names theta# and eta#.

As a note, sigma parameters are not currently renamed; So for the following model (which grabs the parameter automatically labels to generate variables), sigma is simply eps#.

mod <- nonmem2rx(system.file("Theopd.ctl", package="nonmem2rx"), save=FALSE)
mod

You can still rename however you wish, though, using model piping (rxRename() or dplyr::rename() would both work):

mod <- mod %>% rxRename(add.var=eps1)
mod

This model does not specify the residuals in a way that makes sense to nlmixr2. If you want, you can still convert the rxode2 model to a nlmixr2 fit.

Technical details about reading NONMEM to rxode2

The key files to import are the NONMEM control stream (or related file) and the NONMEM output (often with a .lst or .res extension).

The import process steps are below:



Try the nonmem2rx package in your browser

Any scripts or data that you put into this service are public.

nonmem2rx documentation built on April 3, 2025, 11:05 p.m.