Learn R Programming

NMdata

A fast R package for efficient data preparation, consistency-checking and post-processing in PK/PD modeling

Pharmacometrics and PK/PD modeling offers unique information for decision-making in several steps of drug development. However, it often takes a lot of work to get there, and there are many pitfalls along the way. NMdata helps simplifying this work and steering around the pitfalls or at least making sure we didn’t fall into them.

Flexibility first

Any functionality in the NMdata can be used independently of the rest of the package, and NMdata is not intended to force you to change any habits or preferences. Instead, NMdata tries to fit in with how you (or your colleague who worked on the project before you) do things. It likely provides helpful additions no matter what other tools you already use.

Automate book keeping and focus on modeling

Preparing data sets - and if you use NONMEM, reading the results data - can be tedious, and mistakes can lead to hours of frustration. NMdata provides useful tools (including automated checks) for these trivial tasks. Highlights in data set preparation and data checking:

  • mergeCheck() Require left-join merging to only add columns - and nothing else. If rows get duplicated or disappear, throw an error.
  • addTAPD() Automatically add time after previous dose, previous dose amount, cumulative number of doses and other related columns. Works with ADDL/II notation too.
  • flagsAssign() and flagsCount() Automatically assign exclusion flags to data and tabulate number of subjects and observations excluded and/or retained due to each step.
  • NMorderColumns Order columns in a Nonmem data set consistently and intuitively.
  • NMwriteData() Feature-rich data writer for Nonmem data sets. Can return text to be used for $INPUT and $DATA sections.
  • NMcheckData() Rigorous and extensive checking for structural errors and potential issues in Nonmem data sets.
  • NMcheckColnames.R() Check data set against INPUT section of control streams.

Check out this vignette on data preparation.

Read model results in a consistent table structure

While NMdata does not organize all results into single objects that can be further processed, it offers efficient functions to read model results. These functions are all built to handle multiple models and return results in simple, consistent structures. Their results can easily be merged as needed. Notice, all of these functions basically just need a control stream path to run.

  • NMscanData() Read and combine $TABLE output and input data. Feature-rich with support for the vast majority of models. Builds on NMscanInput() to automatically read input data and NMscanTables() to read all the output tables.
  • NMreadExt() A feature-rich processor of ext files. Provides final parameter estimates with uncertainties and everything else provided in the ext file, iterations, objective function value and termination status
  • NMreadParsText() Very flexible processor of comments in control stream parameter sections. As long as the comments provide consistent parameter information in almost any format, NMreadParsText() can turn it into a table.
  • NMreadInits() Read and tabulate initial values, lower, upper limits, FIX and block structures based on parameter sections of control streams.
  • NMrelate() Automatically connect parameters to variable names used in control stream code (say, CL=EXP(THETA(1)+ETA(1)) in control stream and NMrelate will “relate” THETA(1) and ETA(1) to CL. Powerful for QC and even simple parameter table generation.
  • NMreadPhi() Reads individual posthoc estimates into a data.frame
  • NMreadCov() Reads an estimated variance-covariance matrix and formats as a matrix
  • NMreadShk() to read shrinkage tables

Vignettes:
Flexible Creation of Parameter Tables
NMscanData: Find And Combine All Output And Input Data

More information

The best place to browse information about the package is here. The quickest way in is the Cheatsheet. It does not cover any features related to generation of parameter tables, so you may also want to take a look at that vignette.

Also, check out the most recent vignette on Flexible Creation of Parameter Tables using NMdata.

How to install

NMdata is on CRAN and MPN. To install from the package archive you are already using, do:

install.packages("NMdata")
library(NMdata)

See further below for instructions on how to install from other sources than your default archive, if need be.

Prepare, check, and export PK/PD data

On the data-generation side, functionality is provided for documentation of the datasets while generating them. There are functions for automatic checks of (some) data merges, handling and counting of exclusions flags, final preparations for ensuring readability in NONMEM, and ensuring traceability of datasets back to data generation scripts.

Check data as read by NONMEM

The NMcheckData function will do an extensive and fully automated set of checks of the data before you run NONMEM. And did NONMEM not behave? NMcheckData can debug the data as seen by NONMEM. That’s right - it has never been easier to find data bugs.

Get the most recent version

If your archive has not been updated since July 2021, you may not find NMdata if you try to install with install.packages (option 1). In that case you have two other options. You can explicitly select CRAN for the installation. Or if you should want a version that has not yet reached CRAN, installing from Github is easy too.

## Option 1: Install from your default repository
install.packages("NMdata")

## Option 2: Install explicitly from CRAN
install.packages("NMdata",repos="https://cran.r-project.org")

## Option 3: Install from github
library(remotes)
install_github("nmautoverse/NMdata")

If you use the Github version, you may want to see the FAQ for how to install specific releases from Github (ensuring reproducibility).

Questions?

Check the FAQ, or ask on github

Issues?

The best way to report a bug or to request features is on github.

Code of Conduct

Please note that the patchwork project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Copy Link

Version

Install

install.packages('NMdata')

Monthly Downloads

668

Version

0.2.3

License

MIT + file LICENSE

Maintainer

Philip Delff

Last Published

January 11th, 2026

Functions in NMdata (0.2.3)

NMexpandDoses

Transform repeated dosing events (ADDL/II) to individual dosing events
NMreadCsv

Read input data formatted for Nonmem
NMgenText

Generate text for INPUT and possibly DATA sections of NONMEM control streams.
NMreadCov

Read covariance matrix from `.cov` file
NMextractDataFile

Extract the data file used in a control stream
NMisNumeric

Test if a variable can be interpreted by Nonmem
NMorderColumns

Standardize column order in Nonmem input data
NMreadExt

Read information from Nonmem ext files
NMextractText

Versatile text extractor from Nonmem (input or output) control streams
NMinfo

Get metadata from an NMdata object
NMreadShk

Read Shrinkage data reported by Nonmem
NMreadTabSlow

Read Nonmem table files without assumptions about what tables they contain
NMreadInits

Tabulate information from parameter sections in control streams
NMrelate

Relate parameter names and variables based on control stream code sections.
NMreadSizes

Read SIZES info from a control stream
NMreadPhi

Read information from Nonmem phi files
NMreadParsText

Read comments to parameter definitions in Nonmem control streams
NMreadTab

Read an output table file from Nonmem
NMreadSection

Extract sections of Nonmem control streams
NMreadFilters

Read data filters from a NONMEM model
NMreplaceDataFile

Replace data file used in Nonmem control stream
NMscanInput

Find and read input data and optionally translate column names according to the $INPUT section
NMtransInp

translate the column names according to the $INPUT section of a control stream
NMscanData

Automatically find Nonmem input and output tables and organize data
NMwriteData

Write dataset for use in Nonmem (and R)
addBlocks

Add blocking info to parameter set
NMwriteSection

Replace ($)sections of a Nonmem control stream
NMstamp

stamp a dataset or any other object
NMscanMultiple

Run NMscanData on multiple models and stack results
NMscanTables

Find and read all output data tables in Nonmem run
addOmegaCorr

Deprecated: use addCor. Add correlations to parameter table
addTAPD

Add time since previous dose to data, time of previous dose, most recent dose amount, cumulative number of doses, and cumulative dose amount.
as.NMctl

Convert object to class NMctl
checkColRow

check that col.row is not edited in Nonmem control stream
addCor

add correlations of off-diagonal OMEGA and SIGMA elements to a parameter table
cl

Define a vector with factor levels in the same order as occurring in the vector.
cc

Create character vectors without quotation marks
addParameter

add parameter based on par.type and i,j
addParType

Fill parameter names indexes in a data set
addSameBlocks

Create a variable in inital value table to keep track of SAME blocks i.e. parameters that are part of a single distribution
dt2mat

Convert a data.table of parameter estimates to a matrix
count_ij

Assign i and j indexes based on parameter section text
deprecatedArg

Report if an argument is deprecated.
compareCols

Compare elements in lists with aim of combining
dtFillCols

Create a data table with input columns of unequal length
colLabels

Extract column labels as defined in SAS
dtapply

Apply function and return a data.frame
dims

Get dimensions of multiple objects
dcastSe

A standard-evaluation interface to `data.table::dcast()`
cleanSpaces

Drop leading, trailing and repeated spaces in character strings
egdt

Expand grid of data.tables
editCharCols

Replace strings in character character columns of a data set
findCovs

Extract columns that vary within values of other columns
escape.charclass

Escape selected special characters with backslashes
fnAppend

paste something before file name extension.
flagsAssign

Assign exclusion flags to a dataset based on specified table
findVars

Extract columns that vary within values of other columns in a data.frame
flagsCount

Create an overview of number of retained and discarded datapoints.
fnExtension

Change file name extension
lapplydt

Apply function of subsets of `data.frame`, return named list
is.NMdata

Check if an object is 'NMdata'
itriag

Row numbers of elements in a triangular representation of a symmetric matrix
jtriag

Column numbers of elements in a triangular representation of a symmetric matrix
getLines

read lines as needed
filePathSimple

Clean and standardize file system paths
initsToExt

Convert inits elements to a parameter data.frame
getArgs

Get provided arguments as a named list
getFilePaths

Internal interpretation of file specification options
listMissings

List rows with missing values across multiple columns
lstExtractTime

Extract run time from output control stream
mergeCoal

Overwrite values in one data.frame as available in another.
message_dt

print a data.table
readCtl

Read as class NMctl
mat2dt

upper or lower triangle or all values of a matrix as long-format
renameByContents

Rename columns matching properties of data contents
print.summary_NMdata

print method for NMdata summaries
mergeCheck

Merge, order, and check resulting rows and columns.
reduceTables

reduce tables from NMscanTables to fewer objects
messageWrap

Pretty wrapping of lines in NMdata vignettes
searchColRow

Check row identifier in a model for necessary properties.
uniquePresent

Extract unique non-missing value from vector
writeNMinfo

Do the actual writing of meta data
summary.NMdata

summary method for NMdata objects
triagSize

Calculate number of elements for matrix specification
unNMdata

Remove NMdata class and discard NMdata meta data
splitFields

splitFields splits the fields format string into the splitters and the variable names. NB, this is interpreting the user-provided fields, it is not looking at control stream text,
tryCatchAll

Catch errors, warnings, messages
tmpcol

generate a name for a new data column that is not already in use.
NMdataGetOption

Look up default configuration of an argument
NMcheckColnames

Compare $INPUT in control stream to column names in input data
NMdataOperations

Basic arithmetic on NMdata objects
NMcheckData

Check data for Nonmem compatibility or check control stream for data compatibility
NMdataConf

Configure default behavior of NMdata functions
NMdataDecideOption

Determine active parameter value based on argument and NMdataConf setting
NMapplyFilters

Translate Nonmem filters to R code and apply to data
NMcheckDataFile

check input data based on control stream
NMcode2R

Translate Nonmem $PK, $PRED sections or other Nonmem code to R code
NMdataConfOptions

Get NMdataConf parameter properties