Skip to content

Commit

Permalink
remove nm_fdata from this PR
Browse files Browse the repository at this point in the history
 - opting to separate this into a separate, more focused PR
  • Loading branch information
barrettk committed Jul 15, 2024
1 parent 2abd55c commit d23855e
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 97 deletions.
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 0 additions & 12 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
56 changes: 1 addition & 55 deletions R/run-nmtran.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 1 addition & 11 deletions man/nmtran.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions man/print_bbi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions tests/testthat/test-workflow-bbi.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d23855e

Please sign in to comment.