From 789a7306b80a41e98564eb64fd31eeafec4de4c5 Mon Sep 17 00:00:00 2001 From: Andrew Santulli Date: Sun, 17 Mar 2024 23:05:24 -0400 Subject: [PATCH] small fix to previous commit and update examples in help docs --- R/load_nonmem.R | 21 +++++++++++++-------- R/nonmem2mrgsolve.R | 24 +++++++++++++++--------- R/writemrgsolve.R | 4 ++-- man/load_ctl.Rd | 8 +++++--- man/load_ext.Rd | 10 ++++++---- man/nonmem2mrgsolve.Rd | 24 +++++++++++++++--------- man/writemrgsolve.Rd | 4 ++-- 7 files changed, 58 insertions(+), 37 deletions(-) diff --git a/R/load_nonmem.R b/R/load_nonmem.R index 7e5b1db..db8fc33 100644 --- a/R/load_nonmem.R +++ b/R/load_nonmem.R @@ -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 = ""){ @@ -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){ @@ -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) @@ -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 diff --git a/R/nonmem2mrgsolve.R b/R/nonmem2mrgsolve.R index 8c43fe3..8455d93 100644 --- a/R/nonmem2mrgsolve.R +++ b/R/nonmem2mrgsolve.R @@ -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){ diff --git a/R/writemrgsolve.R b/R/writemrgsolve.R index 1803df3..baf7ddd 100644 --- a/R/writemrgsolve.R +++ b/R/writemrgsolve.R @@ -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 diff --git a/man/load_ctl.Rd b/man/load_ctl.Rd index 196ef95..2ba74c5 100644 --- a/man/load_ctl.Rd +++ b/man/load_ctl.Rd @@ -7,7 +7,7 @@ load_ctl(filename = NULL, dir = "") } \arguments{ -\item{filename}{String of the NONMEM model file name without the .ctl extension} +\item{filename}{String of the NONMEM model name without the .ctl extension} \item{dir}{String of the directory path to the NONMEM run files} } @@ -15,9 +15,11 @@ load_ctl(filename = NULL, dir = "") R dataframe of the NONMEM ctl file } \description{ -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. } \examples{ -load_ctl() +load_ctl(filename = "nonmem-model", dir = "path/to/directory/") + +load_ctl(filename = "/path/to/directory/nonmem-model") } diff --git a/man/load_ext.Rd b/man/load_ext.Rd index 0172b1b..beb970d 100644 --- a/man/load_ext.Rd +++ b/man/load_ext.Rd @@ -7,21 +7,23 @@ load_ext(filename = NULL, dir = "", sigdig = -1, use.cnv = F) } \arguments{ -\item{filename}{String of the NONMEM model file name without the .ext extension} +\item{filename}{String of the NONMEM model name without the .ext extension} \item{dir}{String of the directory path to the NONMEM run files} \item{sigdig}{Numeric of the number of significant digits to round non-fixed thetas and etas to; -1 for no rounding} -\item{use.cnv}{Logical for whether to use NONMEM cnv file final parameter estimates instead of ext estimates (\code{T} or \code{F})} +\item{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})} } \value{ R list of the NONMEM final OFV, parameter estimates, and IIV magnitudes } \description{ -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. } \examples{ -load_ext() +load_ext(filename = "nonmem-model", dir = "path/to/directory/") + +load_ext(filename = "/path/to/directory/nonmem-model") } diff --git a/man/nonmem2mrgsolve.Rd b/man/nonmem2mrgsolve.Rd index d5e802f..375299c 100644 --- a/man/nonmem2mrgsolve.Rd +++ b/man/nonmem2mrgsolve.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/nonmem2mrgsolve.R \name{nonmem2mrgsolve} \alias{nonmem2mrgsolve} -\title{Convert NONMEM run into mrgsolve code} +\title{Automated NONMEM to mrgsolve Translation} \usage{ nonmem2mrgsolve( filename = NULL, @@ -15,27 +15,33 @@ nonmem2mrgsolve( ) } \arguments{ -\item{filename}{String of the NONMEM model file name without any extension} +\item{filename}{String of the NONMEM model name with or without the .ctl extension} -\item{dir}{String of the directory path to the NONMEM run files} +\item{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)} \item{sigdig}{Numeric of the number of significant digits to round non-fixed thetas and etas to; default NULL for no rounding} -\item{write}{Logical for whether to write the mrgsolve code output to a R file (\code{T} or \code{F})} +\item{write}{Logical for whether to write the mrgsolve code to an R file (\code{T} or \code{F})} -\item{return.orig}{Logical for whether to output the originally read in NONMEM ctl and ext files (\code{T} or \code{F})} +\item{return.orig}{Logical for whether to output the original NONMEM ctl and ext files (\code{T} or \code{F})} -\item{out.filename}{String of the file name without extension for the mrgsolve code output R file} +\item{out.filename}{String of the name for the mrgsolve output file without the .R extension} -\item{use.cnv}{Logical for whether to use NONMEM cnv file final parameter estimates instead of ext estimates (\code{T} or \code{F})} +\item{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})} } \value{ R dataframe of the mrgsolve code } \description{ -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. } \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") } diff --git a/man/writemrgsolve.Rd b/man/writemrgsolve.Rd index 8bcfc11..2f1bec1 100644 --- a/man/writemrgsolve.Rd +++ b/man/writemrgsolve.Rd @@ -7,9 +7,9 @@ writemrgsolve(mrg_code = NULL, filename = "mrgsolve_code0", dir = NULL) } \arguments{ -\item{mrg_code}{Dataframe of the NONMEM run translated into mrgsolve code format} +\item{mrg_code}{Dataframe of the NONMEM model translated into mrgsolve code} -\item{filename}{String of the file name for the output mrgsolve code R file} +\item{filename}{String of the name for the mrgsolve output file without the .R extension} \item{dir}{String of the directory path to the NONMEM run files} }