11  Create NONMEM $INPUT

We can use the spec object to create code that goes directly into a NONMEM control stream as the $INPUT block. nm_input() will by default cat the code to your console for copy/paste into the control stream.

spec <- ys_help$spec()

nm_input(spec)
$INPUT
C NUM ID SUBJ=DROP TIME SEQ CMT EVID AMT DV AGE WT CRCL ALB BMI
AAG SCR AST ALT HT CP TAFD TAD LDOS MDV BLQ PHASE STUDY RF=DROP

nm_input() will by default drop columns with character type.

The text is returned invisibly, so if you just want the code returned

txt <- nm_input(spec, .cat = FALSE)

head(txt)
[1] "$INPUT"                                                         
[2] "C NUM ID SUBJ=DROP TIME SEQ CMT EVID AMT DV AGE WT CRCL ALB BMI"
[3] "AAG SCR AST ALT HT CP TAFD TAD LDOS MDV BLQ PHASE STUDY RF=DROP"

11.1 Drop columns

Pass column names in via the .drop argument to drop them from the problem

nm_input(spec, .drop = "PHASE, STUDY")
$INPUT
C NUM ID SUBJ=DROP TIME SEQ CMT EVID AMT DV AGE WT CRCL ALB BMI
AAG SCR AST ALT HT CP TAFD TAD LDOS MDV BLQ PHASE=DROP
STUDY=DROP RF=DROP

11.2 Rename columns

You can rename columns with <new name> = <old name> syntax.

nm_input(spec, .drop = "TIME", TIME = TAFD)
$INPUT
C NUM ID SUBJ=DROP TIME=DROP SEQ CMT EVID AMT DV AGE WT CRCL ALB
BMI AAG SCR AST ALT HT CP TIME=TAFD TAD LDOS MDV BLQ PHASE STUDY
RF=DROP

11.3 Long output

Use the .long argument to get a long, annotated version of $INPUT

spek <- ys_select(spec, C:WT)
nm_input(spek, .long = TRUE)
$INPUT
C         ; comment character
NUM       ; record number
ID        ; subject identifier
SUBJ=DROP ; subject identifier
TIME      ; TIME
SEQ       ; SEQ
CMT       ; compartment number
EVID      ; event ID
AMT       ; dose amount
DV        ; dependent variable
AGE       ; age
WT        ; weight

11.4 Long, verbose output

You can also get more verbose output

spek <- ys_select(spec, HT:RF)
nm_input(spek, .long = TRUE, .decodes = TRUE)
$INPUT
HT      ; height
CP      ; Child-Pugh score 
        ; [0 = normal, 1 = Pugh1, 2 = Pugh2, 3 = Pugh3]
TAFD    ; time after first dose
TAD     ; time after dose
LDOS    ; last dose amount
MDV     ; MDV 
        ; [0 = non-missing, 1 = missing]
BLQ     ; below limit of quantification 
        ; [0 = above QL, 1 = below QL]
PHASE   ; study phase indicator 
        ; [values: 1]
STUDY   ; study number 
        ; [1 = SAD, 2 = MAD, 3 = Renal, 4 = Hepatic]
RF=DROP ; renal function stage