% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nm_helpers.R
\name{build_nm_dataset}
\alias{build_nm_dataset}
\title{Build a NONMEM-Format Dataset from DM/EX/PC}
\usage{
build_nm_dataset(
  DM,
  EX,
  PC,
  IDs = NULL,
  id_prefix = "",
  id_func = NULL,
  dose_cmt = 1L,
  verbose = FALSE
)
}
\arguments{
\item{DM}{data.frame with one row per subject.  Must contain SUBJID; any
other columns are merged in as subject-level constants.}

\item{EX}{dose records (see \code{\link{build_dose_records}}).}

\item{PC}{observation records (see \code{\link{build_obs_records}}).}

\item{IDs}{character vector of SUBJIDs to keep.  NULL (default) is the
intersect of EX and PC where DV > 0.}

\item{id_prefix}{character.  When \code{id_func} is NULL,
ID = paste0(id_prefix, SUBJID).}

\item{id_func}{function(SUBJID) -> character ID.  Overrides \code{id_prefix}.}

\item{dose_cmt}{default compartment for dose records lacking a CMT column.}

\item{verbose}{print progress. Default FALSE.}
}
\value{
data.frame with columns
  ID, SUBJID, DAT2, TIME, AMT, RATE, CMT, DV, MDV, <DM-columns ...>.
}
\description{
Build a NONMEM-format dataset from cleaned DM/EX/PC tables.
Time-varying covariates (VS, LB, ...) are NOT merged here.  Use
\code{\link{merge_cov_locf}} afterwards to add them.  CRCL is added
separately via \code{\link{add_crcl_cg}}.  Molar conversion is done with
\code{\link{nm_to_molar}}.
}
\details{
Records are sorted by SUBJID, DAT2, TIME, CMT, MDV, AMT.  At tied
(SUBJID, DAT2, TIME, CMT, MDV), AMT = 0 (observation) sorts before AMT > 0
(dose) so a pre-dose observation precedes the dose given at the same minute.
}
