diff --git a/R/load_nonmem.R b/R/load_nonmem.R index 21955f5..af6df77 100644 --- a/R/load_nonmem.R +++ b/R/load_nonmem.R @@ -1,171 +1,208 @@ -## Loading Nonmem Files #### - -## FUNCTION LOAD CTL #### - -#' Load NONMEM ctl file into R -#' -#' Loads the NONMEM ctl file into R for translation to mrgsolve format. -#' -#' @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(filename = "nonmem-model", dir = "path/to/directory/") -#' -#' @export -load_ctl <- function(filename = NULL, dir = ""){ - - ctl <- read.delim2(paste0(dir,filename,".ctl"), header = F) %>% - dplyr::mutate(V1 = trimws(V1, which = "both"))%>% # remove leading and trailing white space - dplyr::filter(substr(V1,1,1) != ";", V1 != "")%>% # remove white space or comment rows - dplyr::mutate(V1 = gsub(";.*","",V1))%>% # remove anything after comment - dplyr::mutate(FLG_BLOCK = ifelse(startsWith(V1, "$"), 1, 0))%>% # flag beginning of each block - dplyr::mutate(BLOCK = suppressWarnings(ifelse(FLG_BLOCK == 1, trimws(substr(V1,2,6), which = "both"), NA)))%>% # get block name - dplyr::mutate(BLOCK = zoo::na.locf(BLOCK, na.rm = F, fromLast = F)) # pull block name down until next block starts - - return(ctl) -} - -## FUNCTION LOAD EXT #### - -#' Load NONMEM ext file into R -#' -#' Loads the NONMEM ext file into R for capture of the final estimates. -#' -#' @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 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(filename = "nonmem-model", dir = "path/to/directory/") -#' -#' @export -load_ext <- function(filename = NULL, dir = "", sigdig = -1, use.cnv = F){ - - ext00 <- read.table(paste0(dir,filename,".ext"),sep='',header=T,fill=T,na.strings=".", skip=1) - - if(class(ext00$ITERATION) != "numeric"){ - for(i in 1:ncol(ext00)){ - ext00[,i] <- as.numeric(ext00[,i]) - } - rm(i) - } - - if(use.cnv == T){ - - ext0 <- read.table(paste0(dir,filename,".cnv"),sep='',header=T,fill=T,na.strings =".",skip=1)%>% - dplyr::filter(ITERATION == -2000000000) - - }else{ - - ext0 <- ext00 %>% - dplyr::filter(ITERATION == -1000000000) %>% # NONMEM User Guide VIII for definition (final estimates) - dplyr::filter(dplyr::row_number() == max(dplyr::row_number())) - } - - tmpfixed <- ext00 %>% - dplyr::filter(ITERATION == -1000000006) %>% # NONMEM User Guide VIII for definition (fixed parameters) - dplyr::filter(dplyr::row_number() == max(dplyr::row_number())) - - if(sigdig > 0){ - omnofix <- tmpfixed[1,dplyr::starts_with("OMEGA", vars = colnames(tmpfixed))] - - if(class(omnofix)=="numeric"){ # 3/17/2024 fix load when only 1 IIV - omnofix <- data.frame("OMEGA.1.1." = omnofix) - } - - omnofix <- colnames(omnofix[which(omnofix[1,] != 1)]) - - if(length(omnofix)>0){ # 3/17/2024 fix load when all IIV fixed - tmpomnofix <- lapply(1:length(omnofix), function(i){ - nofixtmpa <- strsplit(trimws(omnofix[[i]]),"\\.") - return(data.frame(R = as.numeric(nofixtmpa[[1]][2]), C = as.numeric(nofixtmpa[[1]][3]))) - }) - omnofix <- dplyr::bind_rows(tmpomnofix) - }else{ - omnofix <- NULL - } - }else{ - omnofix <- NULL - } - - ext <- list(NITER = NA, OFV = NA, THETA = NA, OMEGA = NA) - - ext$NITER <- max(ext00$ITERATION) - ext$OFV <- ext0[1,which(substr(colnames(ext0),nchar(colnames(ext0))-2,nchar(ext0)) == "OBJ")] - ext$THETA <- ext0[1,dplyr::starts_with("THETA",vars = colnames(ext0))] - - tmpom0 <- ext0[1,dplyr::starts_with("OMEGA",vars = colnames(ext0))] - if(class(tmpom0)=="numeric"){ # 3/17/2024 fix load when only 1 IIV - tmpom0 <- data.frame("OMEGA.1.1." = tmpom0) - } - - tmpn <- strsplit(trimws(colnames(tmpom0)[ncol(tmpom0)]), "\\.") - tmpn <- as.numeric(tmpn[[1]][length(tmpn[[1]])]) - - tmpom2 <- matrix(data = 0, ncol = tmpn, nrow = tmpn) - colnames(tmpom2) <- paste0("OMEGA",1:tmpn) - rownames(tmpom2) <- paste0("OMEGA",1:tmpn) - - tmpom <- tmpom0[1, which(tmpom0 != 0)] - if(class(tmpom)=="numeric"){ # 3/17/2024 fix load when only 1 IIV - tmpom_val <- tmpom - tmpom <- data.frame() - tmpom[1,colnames(tmpom0)[which(tmpom0!=0)]] = tmpom_val - } - - if(length(tmpom)>0){ # 3/17/2024 fix error all IIV fixed to zero - for(i in 1:length(tmpom)){ - - tmp <- strsplit(trimws(colnames(tmpom)[i]),"\\.")[[1]] - tmpr <- as.numeric(tmp[2]) - tmpc <- as.numeric(tmp[3]) - - if(sigdig > 0 & !is.null(omnofix)){ # 3/17/2024 fix load when all iiv fixed - - omvalround <- tmpom[1,i] - - tmpa <- which(omnofix$R == tmpr) - - if(length(tmpa)>0){ - - tmpa <- omnofix[tmpa,] - tmpa <- which(tmpa$C == tmpc) - - if(length(tmpa)>0){ - - omvalround <- signif(tmpom[1,i], sigdig) - } - } - - tmpom2[tmpr,tmpc] <- omvalround - tmpom2[tmpc,tmpr] <- omvalround - - }else{ - - tmpom2[tmpr,tmpc] <- tmpom[1,i] - tmpom2[tmpc,tmpr] <- tmpom[1,i] - } - } - } - - ext$OMEGA <- tmpom2 - - if(sigdig > 0){ - - thnofix <- which(tmpfixed[1,dplyr::starts_with("THETA",vars = colnames(tmpfixed))] != 1) - - if(length(thnofix)>0){ - ext[["THETA"]][thnofix] <- signif(ext[["THETA"]][thnofix],sigdig) - } - } - - return(list(ext=ext,ext0=ext0)) -} - -## END #### +## Loading Nonmem Files #### + +## FUNCTION LOAD CTL #### + +#' Load NONMEM ctl (or mod) file into R +#' +#' Loads the NONMEM ctl (or mod) file into R for translation to mrgsolve format. +#' +#' @param filename String of the NONMEM model name without the .ctl (or .mod) extension +#' @param dir String of the directory path to the NONMEM run files +#' +#' @return R dataframe of the NONMEM ctl (or mod) file +#' +#' @examples +#' # load_ctl(filename = "nonmem-model", dir = "path/to/directory/") +#' +#' @export +load_ctl <- function(filename = NULL, dir = ""){ + + ctl <- try(suppressWarnings(read.delim2(paste0(dir,filename,".ctl"), header = F)),silent=T) + + if(class(ctl)=="try-error"){ + ctl <- try(suppressWarnings(read.delim2(paste0(dir,filename,".mod"), header = F)),silent=T) + } + + if(class(ctl)=="try-error"){ + err_msg <- ctl[1] + ctl <- NULL + } + + if(!is.null(ctl)){ + ctl <- ctl %>% + dplyr::mutate(V1 = trimws(V1, which = "both"))%>% # remove leading and trailing white space + dplyr::filter(substr(V1,1,1) != ";", V1 != "")%>% # remove white space or comment rows + dplyr::mutate(V1 = gsub(";.*","",V1))%>% # remove anything after comment + dplyr::mutate(FLG_BLOCK = ifelse(startsWith(V1, "$"), 1, 0))%>% # flag beginning of each block + dplyr::mutate(BLOCK = suppressWarnings(ifelse(FLG_BLOCK == 1, trimws(substr(V1,2,6), which = "both"), NA)))%>% # get block name + dplyr::mutate(BLOCK = zoo::na.locf(BLOCK, na.rm = F, fromLast = F)) # pull block name down until next block starts + + print("NONMEM Control Stream Successfully Loaded") + }else{ + print("NONMEM Control Stream Failed to Load") + print(err_msg) + } + + return(ctl) +} + +## FUNCTION LOAD EXT #### + +#' Load NONMEM ext file into R +#' +#' Loads the NONMEM ext file into R for capture of the final estimates. +#' +#' @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 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(filename = "nonmem-model", dir = "path/to/directory/") +#' +#' @export +load_ext <- function(filename = NULL, dir = "", sigdig = -1, use.cnv = F){ + + ext00 <- try(suppressWarnings(read.table(paste0(dir,filename,".ext"),sep='',header=T,fill=T,na.strings=".", skip=1)),silent=T) + + if(class(ext00) != "try-error"){ + if(class(ext00$ITERATION) != "numeric"){ + for(i in 1:ncol(ext00)){ + ext00[,i] <- as.numeric(ext00[,i]) + } + rm(i) + } + } + + if(use.cnv == T){ + + ext0 <- try(suppressWarnings(read.table(paste0(dir,filename,".cnv"),sep='',header=T,fill=T,na.strings =".",skip=1)),silent=T) + + if(class(ext0) != "try-error"){ + ext0 <- ext0 %>% + dplyr::filter(ITERATION == -2000000000) + }else{ + ext0 <- NULL + } + }else{ + + if(class(ext00) != "try-error"){ + ext0 <- ext00 %>% + dplyr::filter(ITERATION == -1000000000) %>% # NONMEM User Guide VIII for definition (final estimates) + dplyr::filter(dplyr::row_number() == max(dplyr::row_number())) + }else{ + ext0 <- NULL + } + } + + if(!is.null(ext0)){ + + print("NONMEM Final Estimates Successfully Loaded") + + tmpfixed <- ext00 %>% + dplyr::filter(ITERATION == -1000000006) %>% # NONMEM User Guide VIII for definition (fixed parameters) + dplyr::filter(dplyr::row_number() == max(dplyr::row_number())) + + if(sigdig > 0){ + omnofix <- tmpfixed[1,dplyr::starts_with("OMEGA", vars = colnames(tmpfixed))] + + if(class(omnofix)=="numeric"){ # 3/17/2024 fix load when only 1 IIV + omnofix <- data.frame("OMEGA.1.1." = omnofix) + } + + omnofix <- colnames(omnofix[which(omnofix[1,] != 1)]) + + if(length(omnofix)>0){ # 3/17/2024 fix load when all IIV fixed + tmpomnofix <- lapply(1:length(omnofix), function(i){ + nofixtmpa <- strsplit(trimws(omnofix[[i]]),"\\.") + return(data.frame(R = as.numeric(nofixtmpa[[1]][2]), C = as.numeric(nofixtmpa[[1]][3]))) + }) + omnofix <- dplyr::bind_rows(tmpomnofix) + }else{ + omnofix <- NULL + } + }else{ + omnofix <- NULL + } + + ext <- list(NITER = NA, OFV = NA, THETA = NA, OMEGA = NA) + + ext$NITER <- max(ext00$ITERATION) + ext$OFV <- ext0[1,which(substr(colnames(ext0),nchar(colnames(ext0))-2,nchar(ext0)) == "OBJ")] + ext$THETA <- ext0[1,dplyr::starts_with("THETA",vars = colnames(ext0))] + + tmpom0 <- ext0[1,dplyr::starts_with("OMEGA",vars = colnames(ext0))] + if(class(tmpom0)=="numeric"){ # 3/17/2024 fix load when only 1 IIV + tmpom0 <- data.frame("OMEGA.1.1." = tmpom0) + } + + tmpn <- strsplit(trimws(colnames(tmpom0)[ncol(tmpom0)]), "\\.") + tmpn <- as.numeric(tmpn[[1]][length(tmpn[[1]])]) + + tmpom2 <- matrix(data = 0, ncol = tmpn, nrow = tmpn) + colnames(tmpom2) <- paste0("OMEGA",1:tmpn) + rownames(tmpom2) <- paste0("OMEGA",1:tmpn) + + tmpom <- tmpom0[1, which(tmpom0 != 0)] + if(class(tmpom)=="numeric"){ # 3/17/2024 fix load when only 1 IIV + tmpom_val <- tmpom + tmpom <- data.frame() + tmpom[1,colnames(tmpom0)[which(tmpom0!=0)]] = tmpom_val + } + + if(length(tmpom)>0){ # 3/17/2024 fix error all IIV fixed to zero + for(i in 1:length(tmpom)){ + + tmp <- strsplit(trimws(colnames(tmpom)[i]),"\\.")[[1]] + tmpr <- as.numeric(tmp[2]) + tmpc <- as.numeric(tmp[3]) + + if(sigdig > 0 & !is.null(omnofix)){ # 3/17/2024 fix load when all iiv fixed + + omvalround <- tmpom[1,i] + + tmpa <- which(omnofix$R == tmpr) + + if(length(tmpa)>0){ + + tmpa <- omnofix[tmpa,] + tmpa <- which(tmpa$C == tmpc) + + if(length(tmpa)>0){ + + omvalround <- signif(tmpom[1,i], sigdig) + } + } + + tmpom2[tmpr,tmpc] <- omvalround + tmpom2[tmpc,tmpr] <- omvalround + + }else{ + + tmpom2[tmpr,tmpc] <- tmpom[1,i] + tmpom2[tmpc,tmpr] <- tmpom[1,i] + } + } + } + + ext$OMEGA <- tmpom2 + + if(sigdig > 0){ + + thnofix <- which(tmpfixed[1,dplyr::starts_with("THETA",vars = colnames(tmpfixed))] != 1) + + if(length(thnofix)>0){ + ext[["THETA"]][thnofix] <- signif(ext[["THETA"]][thnofix],sigdig) + } + } + }else{ + ext <- NULL + print("NONMEM Final Estimates Failed to Load") + } + + return(list(ext=ext,ext0=ext0)) +} + +## END #### diff --git a/R/nonmem2mrgsolve.R b/R/nonmem2mrgsolve.R index b001f88..c28c810 100644 --- a/R/nonmem2mrgsolve.R +++ b/R/nonmem2mrgsolve.R @@ -1,82 +1,89 @@ -## FUNCTION MASTER #### - -#' Automated NONMEM to mrgsolve Translation -#' -#' Translates a NONMEM model into mrgsolve syntax using the NONMEM ctl and ext (or cnv) 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 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 -#' # setwd("path/to/directory") -#' # nonmem2mrgsolve::nonmem2mrgsolve(filename = "nonmem-model.ctl") -#' -#' @export -nonmem2mrgsolve <- function(filename = NULL, dir = NULL, sigdig = NULL, write = T, return.orig = F, out.filename = NULL, use.cnv = F){ - - keep_block <- c("PROB", "PROBL", "PROBLEM", "INPUT", "MODEL", "PK", "DES", "TABLE") - - in.filename <- gsub(".ctl","",filename) - - tsigdig <- ifelse(!is.null(sigdig), sigdig, -1) - tdir <- ifelse(!is.null(dir), paste0(dir,"/"), "") - tusecnv <- ifelse(use.cnv == T, T, F) - - btemp <- load_ext(in.filename, tdir, sigdig = tsigdig, use.cnv = tusecnv) - - ext0 <- btemp$ext0 - ext <- btemp$ext - - ctl0 <- load_ctl(in.filename, tdir) - - ctl <- ctl0 %>% - dplyr::filter(BLOCK %in% keep_block) # filter to useful blocks - - btemp <- get_block_input(ctl,ext) - params <- btemp$params - mrg_code <- btemp$mrg_code - - btemp <- get_block_model(ctl, mrg_code) - mrg_code <- btemp$mrg_code - cmts <- btemp$cmts - - btemp <- get_block_pk(ctl, mrg_code, cmts) - mrg_code <- btemp$mrg_code - params2 <- btemp$params2 - - mrg_code <- get_block_omega(ext0 = ext, mrg_code = mrg_code) - - all_params <- sort(c(params$V1,params2)) - mrg_code <- get_block_table(ctl, mrg_code, all_params, cmts$V1) - - if(write == T){ - - outfile <- paste0("mrgsolve-code-V0_",in.filename) - - if(!is.null(out.filename)){ - if(!is.na(out.filename) & out.filename != "" & out.filename != " "){ - outfile <- out.filename - } - } - - writemrgsolve(mrg_code, outfile, dir = dir) - } - - if(return.orig == T){ - - return(list(mrg_code=mrg_code,ctl0=ctl0,ext0=ext0,ext=ext)) - - }else{ - - return(mrg_code) - } -} - -## END #### +## FUNCTION MASTER #### + +#' Automated NONMEM to mrgsolve Translation +#' +#' Translates a NONMEM model into mrgsolve syntax using the NONMEM ctl (or mod) and ext (or cnv) files. +#' +#' @param filename String of the NONMEM model name with or without the .ctl (or .mod) 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 to an R file (\code{T} or \code{F}) +#' @param return.orig Logical for whether to output the original NONMEM ctl (or mod) and ext (or cnv) 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 +#' # setwd("path/to/directory") +#' # nonmem2mrgsolve::nonmem2mrgsolve(filename = "nonmem-model.ctl") +#' +#' @export +nonmem2mrgsolve <- function(filename = NULL, dir = NULL, sigdig = NULL, write = T, return.orig = F, out.filename = NULL, use.cnv = F){ + + keep_block <- c("PROB", "PROBL", "PROBLEM", "INPUT", "MODEL", "PK", "DES", "TABLE") + + in.filename <- gsub("\\.ctl","",filename) + in.filename <- gsub("\\.mod","",in.filename) + + tsigdig <- ifelse(!is.null(sigdig), sigdig, -1) + tdir <- ifelse(!is.null(dir), paste0(dir,"/"), "") + tusecnv <- ifelse(use.cnv == T, T, F) + + ctl0 <- load_ctl(in.filename, tdir) + + btemp <- load_ext(in.filename, tdir, sigdig = tsigdig, use.cnv = tusecnv) + + ext0 <- btemp$ext0 + ext <- btemp$ext + + if(!is.null(ctl0) && !is.null(ext)){ + ctl <- ctl0 %>% + dplyr::filter(BLOCK %in% keep_block) # filter to useful blocks + + btemp <- get_block_input(ctl,ext) + params <- btemp$params + mrg_code <- btemp$mrg_code + + btemp <- get_block_model(ctl, mrg_code) + mrg_code <- btemp$mrg_code + cmts <- btemp$cmts + + btemp <- get_block_pk(ctl, mrg_code, cmts) + mrg_code <- btemp$mrg_code + params2 <- btemp$params2 + + mrg_code <- get_block_omega(ext0 = ext, mrg_code = mrg_code) + + all_params <- sort(c(params$V1,params2)) + mrg_code <- get_block_table(ctl, mrg_code, all_params, cmts$V1) + + print("NONMEM to Mrgsolve Translation Completed") + + if(write == T){ + + print("Mrgsolve Code is Writing to an R File") + + outfile <- paste0("mrgsolve-code-V0_",in.filename) + + if(!is.null(out.filename)){ + if(!is.na(out.filename) & out.filename != "" & out.filename != " "){ + outfile <- out.filename + } + } + + writemrgsolve(mrg_code, outfile, dir = dir) + } + + if(return.orig == T){ + + return(list(mrg_code=mrg_code,ctl0=ctl0,ext0=ext0,ext=ext)) + + }else{ + + return(mrg_code) + } + } +} + +## END #### diff --git a/R/writemrgsolve.R b/R/writemrgsolve.R index 0e51f1e..77bd9df 100644 --- a/R/writemrgsolve.R +++ b/R/writemrgsolve.R @@ -1,35 +1,37 @@ -## FUNCTION WRITE MRGSOLVE #### - -#' Write the mrgsolve code to an R file -#' -#' Writes the mrgsolve code, translated from the input NONMEM run, to an 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 -#' -#' @examples -#' # writemrgsolve() -#' -#' @export -writemrgsolve <- function(mrg_code = NULL, filename = "mrgsolve_code0", dir = NULL){ - - tdir <- ifelse(is.na(dir) | is.null(dir), "", paste0(dir,"/")) - nme_pth <- paste0(tdir,filename,".R") - - file <- file(nme_pth) - - cat("code <- ' ",file=nme_pth,sep="\n\n") - - for(i in 1:nrow(mrg_code)){ - cat(mrg_code[i,"V1"],file=nme_pth,sep = "\n",append=TRUE) - } - - cat("'",file=nme_pth,append = T) - - close(file) -} - -## END #### +## FUNCTION WRITE MRGSOLVE #### + +#' Write the mrgsolve code to an R file +#' +#' Writes the mrgsolve code, translated from the input NONMEM run, to an 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 +#' +#' @examples +#' # writemrgsolve() +#' +#' @export +writemrgsolve <- function(mrg_code = NULL, filename = "mrgsolve_code0", dir = NULL){ + + tdir <- ifelse(is.na(dir) | is.null(dir), "", paste0(dir,"/")) + nme_pth <- paste0(tdir,filename,".R") + + file <- file(nme_pth) + + cat("code <- ' ",file=nme_pth,sep="\n\n") + + for(i in 1:nrow(mrg_code)){ + cat(mrg_code[i,"V1"],file=nme_pth,sep = "\n",append=TRUE) + } + + cat("'",file=nme_pth,append = T) + + close(file) + + print("Mrgsolve Code was Saved to an R File") +} + +## END #### diff --git a/README.Rmd b/README.Rmd index bf65a36..78d9cac 100644 --- a/README.Rmd +++ b/README.Rmd @@ -39,7 +39,7 @@ The resulting mrgsolve code will be wrote to mrgsolve-code-V0_pbpk-101.R within ```{r} nonmem2mrgsolve::nonmem2mrgsolve( - filename = "nonmem-model.ctl", # String of the NONMEM model name with or without the .ctl extension + filename = "nonmem-model.ctl", # String of the NONMEM model name with or without the .ctl (or .mod) extension dir = "./folder", # String of the directory path to the NONMEM files (if not already given in the file name input or the working directory already set) sigdig = NULL, # Numeric of the number of significant digits to round non-fixed thetas and etas to; default NULL for no rounding write = T, # [T or F] for whether to write the resulting mrgsolve code to an R file @@ -86,7 +86,7 @@ Translating the NONMEM model into mrgsolve code is accomplished using a single f ```{r} nonmem2mrgsolve( "mod1.ctl", # the NONMEM run name - "./vignette/models/drugx-oral-1cmt-101/", # path to mod1.ctl and mod1.ext, from the working directory (which was set earlier) + "./vignette/models/drugx-oral-1cmt-101/", # path to mod1.ctl and mod1.ext, from the working directory (which was set earlier) out.filename = "mrgsolve_code_drugx-oral", # name for the mrgsolve code .R output file sigdig = 3 # number of significant digits to report thetas and omegas to within the mrgsolve code (optional) ) diff --git a/README.md b/README.md index 211f1fc..806223d 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ is an intuitive and established framework ``` r nonmem2mrgsolve::nonmem2mrgsolve( - filename = "nonmem-model.ctl", # String of the NONMEM model name with or without the .ctl extension + filename = "nonmem-model.ctl", # String of the NONMEM model name with or without the .ctl (or .mod) extension dir = "./folder", # String of the directory path to the NONMEM files (if not already given in the file name input or the working directory already set) sigdig = NULL, # Numeric of the number of significant digits to round non-fixed thetas and etas to; default NULL for no rounding write = T, # [T or F] for whether to write the resulting mrgsolve code to an R file @@ -132,7 +132,7 @@ single function call: ``` r nonmem2mrgsolve( "mod1.ctl", # the NONMEM run name - "./vignette/models/drugx-oral-1cmt-101/", # path to mod1.ctl and mod1.ext, from the working directory (which was set earlier) + "./vignette/models/drugx-oral-1cmt-101/", # path to mod1.ctl and mod1.ext, from the working directory (which was set earlier) out.filename = "mrgsolve_code_drugx-oral", # name for the mrgsolve code .R output file sigdig = 3 # number of significant digits to report thetas and omegas to within the mrgsolve code (optional) ) diff --git a/man/load_ctl.Rd b/man/load_ctl.Rd index 2ba74c5..f8fbac0 100644 --- a/man/load_ctl.Rd +++ b/man/load_ctl.Rd @@ -2,24 +2,22 @@ % Please edit documentation in R/load_nonmem.R \name{load_ctl} \alias{load_ctl} -\title{Load NONMEM ctl file into R} +\title{Load NONMEM ctl (or mod) file into R} \usage{ load_ctl(filename = NULL, dir = "") } \arguments{ -\item{filename}{String of the NONMEM model name without the .ctl extension} +\item{filename}{String of the NONMEM model name without the .ctl (or .mod) extension} \item{dir}{String of the directory path to the NONMEM run files} } \value{ -R dataframe of the NONMEM ctl file +R dataframe of the NONMEM ctl (or mod) file } \description{ -Loads the NONMEM ctl file into R for translation to mrgsolve format. +Loads the NONMEM ctl (or mod) file into R for translation to mrgsolve format. } \examples{ -load_ctl(filename = "nonmem-model", dir = "path/to/directory/") - -load_ctl(filename = "/path/to/directory/nonmem-model") +# load_ctl(filename = "nonmem-model", dir = "path/to/directory/") } diff --git a/man/load_ext.Rd b/man/load_ext.Rd index beb970d..289ba2e 100644 --- a/man/load_ext.Rd +++ b/man/load_ext.Rd @@ -24,6 +24,4 @@ Loads the NONMEM ext file into R for capture of the final estimates. \examples{ 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 375299c..a7b274f 100644 --- a/man/nonmem2mrgsolve.Rd +++ b/man/nonmem2mrgsolve.Rd @@ -15,7 +15,7 @@ nonmem2mrgsolve( ) } \arguments{ -\item{filename}{String of the NONMEM model name with or without the .ctl extension} +\item{filename}{String of the NONMEM model name with or without the .ctl (or .mod) extension} \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)} @@ -36,12 +36,7 @@ R dataframe of the mrgsolve code Translates a NONMEM model into mrgsolve syntax using the NONMEM ctl and ext (or cnv) files. } \examples{ -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") +# setwd("path/to/directory") +# nonmem2mrgsolve::nonmem2mrgsolve(filename = "nonmem-model.ctl") } diff --git a/man/writemrgsolve.Rd b/man/writemrgsolve.Rd index 2f1bec1..003fda0 100644 --- a/man/writemrgsolve.Rd +++ b/man/writemrgsolve.Rd @@ -20,6 +20,6 @@ R file of the mrgsolve code Writes the mrgsolve code, translated from the input NONMEM run, to an R file. } \examples{ -writemrgsolve() +# writemrgsolve() }