From afe85403fdb78f6cd0aec366a22ab19341dcdafc Mon Sep 17 00:00:00 2001 From: Kyle Barrett Date: Thu, 18 Jul 2024 13:19:10 -0400 Subject: [PATCH] added support for passing specific `bbi_args` to `NM-TRAN` call - still need to add more details to the documentation --- R/run-nmtran.R | 25 ++++++++++++++++++++++--- man/execute_nmtran.Rd | 5 ++++- man/nmtran.Rd | 12 +++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/R/run-nmtran.R b/R/run-nmtran.R index 477009a4..018e0b45 100644 --- a/R/run-nmtran.R +++ b/R/run-nmtran.R @@ -11,6 +11,9 @@ #' correct coding. #' #' @param .mod A `bbr` model object. +#' @param .bbi_args A named list specifying arguments to pass to `NM-TRAN`. +#' Similar to the `.bbi_args` argument defined in [submit_model()], though here +#' only `prdefault`, `tprdefault`, and `maxlim` flags are passed to `NM-TRAN`. #' @param .config_path Path to a bbi configuration file. If `NULL`, the default, #' will attempt to use a `bbi.yaml` in the same directory as the model. #' @param nmtran_exe Path to an `NM-TRAN` executable. If `NULL`, will look for a @@ -37,6 +40,7 @@ NULL #' @export run_nmtran <- function( .mod, + .bbi_args = list(prdefault = TRUE, tprdefault = TRUE, maxlim = 3), .config_path = NULL, nmtran_exe = NULL, delete_on_exit = TRUE @@ -47,6 +51,14 @@ run_nmtran <- function( nmtran_exe <- locate_nmtran(.mod, .config_path, nmtran_exe) nm_ver <- attr(nmtran_exe, "nonmem_version") + # Combine NONMEM submission args + # - The main ones of interest are prdefault, tprdefault, and maxlim, which + # impact the evaluation of `NM-TRAN` + .bbi_args <- parse_args_list(.bbi_args, .mod[[YAML_BBI_ARGS]]) + .bbi_args <- Filter(Negate(is.null), .bbi_args[c("prdefault", "tprdefault", "maxlim")]) + cmd_args <- check_bbi_args(.bbi_args) + + mod_path <- get_model_path(.mod) data_path <- get_data_path_from_ctl(.mod) @@ -78,7 +90,10 @@ run_nmtran <- function( nonmem_version = nm_ver, absolute_model_path = mod_path ), - execute_nmtran(nmtran_exe, mod_path = basename(mod_path), dir = temp_folder) + execute_nmtran( + nmtran_exe, mod_path = basename(mod_path), cmd_args = cmd_args, + dir = temp_folder + ) ) # assign class and return @@ -155,15 +170,19 @@ locate_nmtran <- function(.mod = NULL, .config_path = NULL, nmtran_exe = NULL){ #' #' @param nmtran_exe Path to `NM-TRAN` executable. #' @param mod_path Path of a model to evaluate. Should be relative to `dir`. +#' @param cmd_args A character vector of command line arguments for the `NM-TRAN` +#' execution call #' @param dir Directory in which to execute the command. #' #' @keywords internal -execute_nmtran <- function(nmtran_exe, mod_path, dir = NULL) { +execute_nmtran <- function(nmtran_exe, mod_path, cmd_args = NULL, dir = NULL) { if(is.null(dir)) dir <- "." checkmate::assert_directory_exists(dir) + cmd_args <- if(is.null(cmd_args)) character() else cmd_args + nmtran.p <- processx::process$new( - command = nmtran_exe, wd = dir, + command = nmtran_exe, wd = dir, args = cmd_args, stdout = "|", stderr="|", stdin = file.path(dir, mod_path) ) diff --git a/man/execute_nmtran.Rd b/man/execute_nmtran.Rd index d3b3026a..98627d0e 100644 --- a/man/execute_nmtran.Rd +++ b/man/execute_nmtran.Rd @@ -4,13 +4,16 @@ \alias{execute_nmtran} \title{Execute \code{NM-TRAN} in a given directory} \usage{ -execute_nmtran(nmtran_exe, mod_path, dir = NULL) +execute_nmtran(nmtran_exe, mod_path, cmd_args = NULL, dir = NULL) } \arguments{ \item{nmtran_exe}{Path to \code{NM-TRAN} executable.} \item{mod_path}{Path of a model to evaluate. Should be relative to \code{dir}.} +\item{cmd_args}{A character vector of command line arguments for the \code{NM-TRAN} +execution call} + \item{dir}{Directory in which to execute the command.} } \description{ diff --git a/man/nmtran.Rd b/man/nmtran.Rd index fae2bb6b..7d3f3355 100644 --- a/man/nmtran.Rd +++ b/man/nmtran.Rd @@ -5,11 +5,21 @@ \alias{run_nmtran} \title{Interface for running \code{NM-TRAN} on model objects} \usage{ -run_nmtran(.mod, .config_path = NULL, nmtran_exe = NULL, delete_on_exit = TRUE) +run_nmtran( + .mod, + .bbi_args = list(prdefault = TRUE, tprdefault = TRUE, maxlim = 3), + .config_path = NULL, + nmtran_exe = NULL, + delete_on_exit = TRUE +) } \arguments{ \item{.mod}{A \code{bbr} model object.} +\item{.bbi_args}{A named list specifying arguments to pass to \code{NM-TRAN}. +Similar to the \code{.bbi_args} argument defined in \code{\link[=submit_model]{submit_model()}}, though here +only \code{prdefault}, \code{tprdefault}, and \code{maxlim} flags are passed to \code{NM-TRAN}.} + \item{.config_path}{Path to a bbi configuration file. If \code{NULL}, the default, will attempt to use a \code{bbi.yaml} in the same directory as the model.}