Skip to content

Commit

Permalink
small fix to previous commit and update examples in help docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy00000000000 committed Mar 18, 2024
1 parent 60f888b commit 789a730
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 37 deletions.
21 changes: 13 additions & 8 deletions R/load_nonmem.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

#' Load NONMEM ctl file into R
#'
#' Loads the NONMEM ctl model file into R for translation to mrgsolve format.
#' Loads the NONMEM ctl file into R for translation to mrgsolve format.
#'
#' @param filename String of the NONMEM model file name without the .ctl extension
#' @param filename String of the NONMEM model name without the .ctl extension
#' @param dir String of the directory path to the NONMEM run files
#'
#' @return R dataframe of the NONMEM ctl file
#'
#' @examples
#' load_ctl()
#' load_ctl(filename = "nonmem-model", dir = "path/to/directory/")
#'
#' load_ctl(filename = "/path/to/directory/nonmem-model")
#'
#' @export
load_ctl <- function(filename = NULL, dir = ""){
Expand All @@ -32,17 +34,19 @@ load_ctl <- function(filename = NULL, dir = ""){

#' Load NONMEM ext file into R
#'
#' Loads the NONMEM ext model file into R for capture of the final estimates.
#' Loads the NONMEM ext file into R for capture of the final estimates.
#'
#' @param filename String of the NONMEM model file name without the .ext extension
#' @param filename String of the NONMEM model name without the .ext extension
#' @param dir String of the directory path to the NONMEM run files
#' @param sigdig Numeric of the number of significant digits to round non-fixed thetas and etas to; -1 for no rounding
#' @param use.cnv Logical for whether to use NONMEM cnv file final parameter estimates instead of ext estimates (\code{T} or \code{F})
#' @param use.cnv Logical for whether to use the NONMEM cnv file for final parameter estimates instead of the ext file (\code{T} or \code{F})
#'
#' @return R list of the NONMEM final OFV, parameter estimates, and IIV magnitudes
#'
#' @examples
#' load_ext()
#' load_ext(filename = "nonmem-model", dir = "path/to/directory/")
#'
#' load_ext(filename = "/path/to/directory/nonmem-model")
#'
#' @export
load_ext <- function(filename = NULL, dir = "", sigdig = -1, use.cnv = F){
Expand Down Expand Up @@ -90,6 +94,8 @@ load_ext <- function(filename = NULL, dir = "", sigdig = -1, use.cnv = F){
}else{
omnofix <- NULL
}
}else{
omnofix <- NULL
}

ext <- list(NITER = NA, OFV = NA, THETA = NA, OMEGA = NA)
Expand All @@ -112,7 +118,6 @@ load_ext <- function(filename = NULL, dir = "", sigdig = -1, use.cnv = F){

tmpom <- tmpom0[1, which(tmpom0 != 0)]
if(class(tmpom)=="numeric"){ # 3/17/2024 fix load when only 1 IIV
tmpom_colnm <- colnames(tmpom0)[which(tmpom0!=0)]
tmpom_val <- tmpom
tmpom <- data.frame()
tmpom[1,colnames(tmpom0)[which(tmpom0!=0)]] = tmpom_val
Expand Down
24 changes: 15 additions & 9 deletions R/nonmem2mrgsolve.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
## FUNCTION MASTER ####

#' Convert NONMEM run into mrgsolve code
#' Automated NONMEM to mrgsolve Translation
#'
#' Translates a NONMEM run into mrgsolve code format using the NONMEM ctl and ext files.
#' Translates a NONMEM model into mrgsolve syntax using the NONMEM ctl and ext (or cnv) files.
#'
#' @param filename String of the NONMEM model file name without any extension
#' @param dir String of the directory path to the NONMEM run files
#' @param filename String of the NONMEM model name with or without the .ctl extension
#' @param dir String of the directory path to the NONMEM files (if not already given in the filename input; or if the working directory was not already set)
#' @param sigdig Numeric of the number of significant digits to round non-fixed thetas and etas to; default NULL for no rounding
#' @param write Logical for whether to write the mrgsolve code output to a R file (\code{T} or \code{F})
#' @param return.orig Logical for whether to output the originally read in NONMEM ctl and ext files (\code{T} or \code{F})
#' @param out.filename String of the file name without extension for the mrgsolve code output R file
#' @param use.cnv Logical for whether to use NONMEM cnv file final parameter estimates instead of ext estimates (\code{T} or \code{F})
#' @param write Logical for whether to write the mrgsolve code to an R file (\code{T} or \code{F})
#' @param return.orig Logical for whether to output the original NONMEM ctl and ext files (\code{T} or \code{F})
#' @param out.filename String of the name for the mrgsolve output file without the .R extension
#' @param use.cnv Logical for whether to use the NONMEM cnv file for final parameter estimates instead of the ext file (\code{T} or \code{F})
#'
#' @return R dataframe of the mrgsolve code
#'
#' @examples
#' nonmem2mrgsolve()
#' setwd("path/to/directory")
#' nonmem2mrgsolve::nonmem2mrgsolve(filename = "nonmem-model.ctl")
#'
#' nonmem2mrgsolve::nonmem2mrgsolve(filename = "nonmem-model", dir = "path/to/directory", sigdig = 3, write = T, return.orig = F, out.filename = "mrgsolve-model", use.cnv = F)
#'
#' library(nonmem2mrgsolve)
#' nonmem2mrgsolve(filename = "/path/to/directory/nonmem-model.ctl")
#'
#' @export
nonmem2mrgsolve <- function(filename = NULL, dir = NULL, sigdig = NULL, write = T, return.orig = F, out.filename = NULL, use.cnv = F){
Expand Down
4 changes: 2 additions & 2 deletions R/writemrgsolve.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#'
#' Writes the mrgsolve code, translated from the input NONMEM run, to an R file.
#'
#' @param mrg_code Dataframe of the NONMEM run translated into mrgsolve code format
#' @param filename String of the file name for the output mrgsolve code R file
#' @param mrg_code Dataframe of the NONMEM model translated into mrgsolve code
#' @param filename String of the name for the mrgsolve output file without the .R extension
#' @param dir String of the directory path to the NONMEM run files
#'
#' @return R file of the mrgsolve code
Expand Down
8 changes: 5 additions & 3 deletions man/load_ctl.Rd

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

10 changes: 6 additions & 4 deletions man/load_ext.Rd

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

24 changes: 15 additions & 9 deletions man/nonmem2mrgsolve.Rd

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

4 changes: 2 additions & 2 deletions man/writemrgsolve.Rd

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

0 comments on commit 789a730

Please sign in to comment.