From d23855ef312cb147aae9bf05f8039e090cd57e14 Mon Sep 17 00:00:00 2001 From: Kyle Barrett Date: Mon, 15 Jul 2024 15:43:27 -0400 Subject: [PATCH] remove `nm_fdata` from this PR - opting to separate this into a separate, more focused PR --- NAMESPACE | 2 -- R/aaa.R | 1 - R/print.R | 12 ------- R/run-nmtran.R | 56 +----------------------------- man/nmtran.Rd | 12 +------ man/print_bbi.Rd | 5 --- tests/testthat/test-workflow-bbi.R | 11 ------ 7 files changed, 2 insertions(+), 97 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 7aa7e76e7..6c09f664d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -76,7 +76,6 @@ S3method(print,bbi_nmboot_summary) S3method(print,bbi_nonmem_summary) S3method(print,bbi_process) S3method(print,model_tree_static) -S3method(print,nmtran_fdata) S3method(print,nmtran_process) S3method(print_model_files,default) S3method(submit_model,bbi_base_model) @@ -161,7 +160,6 @@ export(new_bootstrap_run) export(new_ext) export(new_model) export(nm_data) -export(nm_fdata) export(nm_file) export(nm_file_multi_tab) export(nm_grd) diff --git a/R/aaa.R b/R/aaa.R index 9f85ce265..105a70fb1 100644 --- a/R/aaa.R +++ b/R/aaa.R @@ -210,7 +210,6 @@ CONF_LOG_CLASS <- "bbi_config_log_df" SUM_LOG_CLASS <- "bbi_summary_log_df" LOG_DF_CLASS <- "bbi_log_df" NMTRAN_PROCESS_CLASS <- "nmtran_process" -NMTRAN_FDATA_CLASS <- "nmtran_fdata" # YAML keys that are hard-coded YAML_YAML_MD5 <- "yaml_md5" diff --git a/R/print.R b/R/print.R index 12f9ef99f..292f4375f 100644 --- a/R/print.R +++ b/R/print.R @@ -502,18 +502,6 @@ print.nmtran_process <- function(x, ...){ } -#' @describeIn print_bbi Prints the `FDATA`, showing key changes from `nm_data` -#' @export -print.nmtran_fdata <- function(x, ...){ - recs_dropped <- attributes(x)$n_records_dropped - cli::cat_bullet( - paste("Number of records dropped:", col_blue(recs_dropped)), - bullet = "en_dash" - ) - cat("\n") - NextMethod() -} - #' @describeIn print_bbi Draw model tree as a static plot #' @param x plot to display #' @param newpage Logical (T/F). If `TRUE`, draw new (empty) page first. diff --git a/R/run-nmtran.R b/R/run-nmtran.R index 3f989df0f..bfc406c54 100644 --- a/R/run-nmtran.R +++ b/R/run-nmtran.R @@ -8,8 +8,7 @@ #' control stream data and instructions into a form executable by `NONMEM`. #' #' `run_nmtran()` allows users to test their models ahead of submission to ensure -#' correct coding, whereas `nm_fdata()` generates and returns the `NM-TRAN` -#' dataset (`FDATA`) for further analysis and verification. +#' correct coding. #' #' @param .mod A `bbr` model object. #' @param .config_path Path to a bbi configuration file. If `NULL`, the default, @@ -28,9 +27,6 @@ #' # Set the path to an NM-TRAN executable #' run_nmtran(mod, nmtran_exe = "/opt/NONMEM/nm75/tr/NMTRAN.exe") #' -#' # Generate and return `FDATA` -#' fdata <- nm_fdata(mod) -#' #' } #' @name nmtran NULL @@ -91,56 +87,6 @@ run_nmtran <- function( } -#' @describeIn nmtran Executes `run_nmtran` on a `bbi_nonmem_model` and -#' returns the `NM-TRAN` dataset (`FDATA`) -#' @export -nm_fdata <- function( - .mod, - .config_path = NULL, - nmtran_exe = NULL -){ - nmtran_p <- run_nmtran(.mod, .config_path, nmtran_exe, delete_on_exit = FALSE) - on.exit(fs::dir_delete(nmtran_p$run_dir)) - - if(nmtran_p$status_val != 0){ - # trim output - output_lines <- nmtran_p$output_lines[!grepl("^\\s+$", nmtran_p$output_lines)] - rlang::warn( - c( - "NM-TRAN was unsuccessful and returned the following messages:", - paste(output_lines, collapse = "\n") - ) - ) - } - - # Attempt to read in FDATA (even if status_val is not 0) - # - FDATA can still be read in in _some scenarios_ where NM-TRAN fails - fdata_path <- file.path(nmtran_p$run_dir, "FDATA") - if(fs::file_exists(fdata_path)){ - input_data <- nm_data(.mod) %>% suppressMessages() - fdata <- tryCatch({ - nm_file_impl(fdata_path, skip = 0) %>% - stats::setNames(names(input_data)) - }, error = function(cond){ - rlang::inform( - c("FDATA could not be read in:", cond$parent$message) - ) - return(NULL) - }) - - if(!is.null(fdata)){ - attr(fdata, "n_records_dropped") <- nrow(input_data) - nrow(fdata) - } - - # assign class and return - class(fdata) <- c(NMTRAN_FDATA_CLASS, class(fdata)) - return(fdata) - }else{ - return(invisible(NULL)) - } -} - - #' Search for and validate existence of an `NM-TRAN` executable #' #' If `nmtran_exe = NULL`, this will look for a `bbi.yaml` file in the same diff --git a/man/nmtran.Rd b/man/nmtran.Rd index 26527871a..fae2bb6bc 100644 --- a/man/nmtran.Rd +++ b/man/nmtran.Rd @@ -3,12 +3,9 @@ \name{nmtran} \alias{nmtran} \alias{run_nmtran} -\alias{nm_fdata} \title{Interface for running \code{NM-TRAN} on model objects} \usage{ run_nmtran(.mod, .config_path = NULL, nmtran_exe = NULL, delete_on_exit = TRUE) - -nm_fdata(.mod, .config_path = NULL, nmtran_exe = NULL) } \arguments{ \item{.mod}{A \code{bbr} model object.} @@ -32,17 +29,13 @@ generate \code{NM-TRAN} datasets (\code{FDATA}). control stream data and instructions into a form executable by \code{NONMEM}. \code{run_nmtran()} allows users to test their models ahead of submission to ensure -correct coding, whereas \code{nm_fdata()} generates and returns the \code{NM-TRAN} -dataset (\code{FDATA}) for further analysis and verification. +correct coding. } \section{Functions}{ \itemize{ \item \code{run_nmtran()}: Run \code{NM-TRAN} on a model object to validate its control stream for correct coding before submission. -\item \code{nm_fdata()}: Executes \code{run_nmtran} on a \code{bbi_nonmem_model} and -returns the \code{NM-TRAN} dataset (\code{FDATA}) - }} \examples{ \dontrun{ @@ -52,8 +45,5 @@ run_nmtran(mod) # Set the path to an NM-TRAN executable run_nmtran(mod, nmtran_exe = "/opt/NONMEM/nm75/tr/NMTRAN.exe") -# Generate and return `FDATA` -fdata <- nm_fdata(mod) - } } diff --git a/man/print_bbi.Rd b/man/print_bbi.Rd index a6bc482f3..c9a8aed1c 100644 --- a/man/print_bbi.Rd +++ b/man/print_bbi.Rd @@ -7,7 +7,6 @@ \alias{print.bbi_nonmem_summary} \alias{print.bbi_nmboot_summary} \alias{print.nmtran_process} -\alias{print.nmtran_fdata} \alias{print.model_tree_static} \title{Print methods for bbr objects} \usage{ @@ -21,8 +20,6 @@ \method{print}{nmtran_process}(x, ...) -\method{print}{nmtran_fdata}(x, ...) - \method{print}{model_tree_static}(x, newpage = is.null(vp), vp = NULL, ...) } \arguments{ @@ -68,8 +65,6 @@ will make for prettier formatting, especially of table outputs. \item \code{print(nmtran_process)}: Prints the \code{NM-TRAN} evaluation of a \code{bbi_nonmem_model} object -\item \code{print(nmtran_fdata)}: Prints the \code{FDATA}, showing key changes from \code{nm_data} - \item \code{print(model_tree_static)}: Draw model tree as a static plot }} diff --git a/tests/testthat/test-workflow-bbi.R b/tests/testthat/test-workflow-bbi.R index 60350a8f1..dbcb7e1e9 100644 --- a/tests/testthat/test-workflow-bbi.R +++ b/tests/testthat/test-workflow-bbi.R @@ -402,17 +402,6 @@ withr::with_options(list( expect_equal(nmtran_results$status, "NMTRAN successful") }) - it("nm_fdata: integration", { - fdata <- nm_fdata(mod1) - - expect_equal(names(fdata), names(nm_data(mod1))) - - # Test dropped/renamed columns - - # Test failure: incorrect data path - data_path <- "test/this/path/data.csv" - modify_data_path_ctl(mod1, data_path) - }) }) }) # closing withr::with_options