From 761beeaaa0c949eb6fd771b18514b50ab77d1d5d Mon Sep 17 00:00:00 2001 From: Philip Delff Date: Thu, 22 Aug 2024 23:37:26 -0400 Subject: [PATCH] NMreadSection handling of OMEGA, OMEGAP etc --- DESCRIPTION | 2 +- R/NMextractText.R | 9 +++++---- R/NMreadExt.R | 18 +++++++++++------- R/NMreadSection.R | 16 ++++++++++++---- R/NMrelateOne.R | 8 ++++++-- R/NMscanInput.R | 9 +++++++-- R/NMwriteSectionOne.R | 2 +- man/NMreadExt.Rd | 4 +++- man/NMreadParsText.Rd | 2 +- man/NMreadSection.Rd | 3 --- man/mergeCheck.Rd | 4 ++-- 11 files changed, 49 insertions(+), 28 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ce832fbe..a08090f5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: NMdata Type: Package Title: Preparation, Checking and Post-Processing Data for PK/PD Modeling -Version: 0.1.6.923 +Version: 0.1.6.931 Authors@R: c(person(given="Philip", family="Delff", email = "philip@delff.dk", diff --git a/R/NMextractText.R b/R/NMextractText.R index 57ab00af..e3ca578c 100644 --- a/R/NMextractText.R +++ b/R/NMextractText.R @@ -104,9 +104,10 @@ NMextractText <- function(file, lines, text, section, char.section, type <- "all" } if(type=="lst") type <- "res" - - if(!match.exactly){ - section <- substring(section,1,3) + + + if(!match.exactly && section!="."){ + section <- paste0(substring(section,1,min(nchar(section),3)),"[A-Z]*") } @@ -136,7 +137,7 @@ NMextractText <- function(file, lines, text, section, char.section, ) ## Find all the lines that start with the $section - idx.starts <- grep(paste0("^ *",char.section,section),lines) + idx.starts <- grep(paste0("^ *",char.section,section," *"),lines) idx.ends <- grep(paste0("^ *",char.end),lines) ## get the sections diff --git a/R/NMreadExt.R b/R/NMreadExt.R index 707870cf..de607e94 100644 --- a/R/NMreadExt.R +++ b/R/NMreadExt.R @@ -78,25 +78,29 @@ NMreadExt <- function(file,return,as.fun,modelname,col.model,auto.ext,tableno="m #### Section start: Dummy variables, only not to get NOTE's in pacakge checks #### + . <- NULL + blocksize <- NULL + cond <- NULL + eigCor <- NULL + est <- NULL + FIX <- NULL + i <- NULL + iblock <- NULL + imin <- NULL + j <- NULL ITERATION <- NULL - variable <- NULL NMREP <- NULL model <- NULL par.type <- NULL parameter <- NULL - i <- NULL - j <- NULL TABLENO <- NULL table.step <- NULL - FIX <- NULL - est <- NULL - cond <- NULL - eigCor <- NULL partLik <- NULL se <- NULL seStdDevCor <- NULL stdDevCor <- NULL value <- NULL + variable <- NULL ### Section end: Dummy variables, only not to get NOTE's in pacakge checks diff --git a/R/NMreadSection.R b/R/NMreadSection.R index 02270aa2..4916647c 100644 --- a/R/NMreadSection.R +++ b/R/NMreadSection.R @@ -40,7 +40,6 @@ ##' @param keepEmpty Deprecated. See keep.empty. ##' @param keepName Deprecated. See keep.name. ##' @param asOne Deprecated. See as.one. -##' @param cleanSpaces Deprecated. See clean.spaces. ##' @return character vector with extracted lines. ##' @param ... Additional arguments passed to NMextractText ##' @return character vector with extracted lines. @@ -57,12 +56,13 @@ NMreadSection <- function(file=NULL, lines=NULL, text=NULL, section, return="tex ## deprecated arguments keepEmpty, keepName, keepComments, asOne, - cleanSpaces, ...){ + ...){ ## args <- getArgs() args <- getArgs(sys.call(),parent.frame()) as.one <- deprecatedArg("asOne","as.one",args=args) - clean.spaces <- deprecatedArg("cleanSpaces","clean.spaces",args=args) + ## clean.spaces <- deprecatedArg("cleanSpaces","clean.spaces",args=args) + ## if(!missing(cleanSpaces)) rm(cleanSpaces) keep.empty <- deprecatedArg("keepEmpty","keep.empty",args=args) keep.name <- deprecatedArg("keepName","keep.name",args=args) keep.comments <- deprecatedArg("keepComments","keep.comments",args=args) @@ -78,6 +78,13 @@ NMreadSection <- function(file=NULL, lines=NULL, text=NULL, section, return="tex section <- toupper(section) } + match.exactly <- FALSE + if(section!="."){ + + string.start <- substring(sub("^\\$","",cleanSpaces(section)),1,3) + match.exactly <- !string.start%in%c("COV","EST","SIM") + } + res <- NMextractText(file=file, lines=lines, text=text, section=section, ## this wrapper is especially made for "$" sections char.section="\\$", @@ -90,7 +97,8 @@ NMreadSection <- function(file=NULL, lines=NULL, text=NULL, section, return="tex clean.spaces=clean.spaces, ## we only consider the model definition, not results. type="mod", - match.exactly=FALSE, + ## match.exactly=FALSE, + match.exactly=match.exactly, ## deprecated args ## keepEmpty=keepEmpty, ## keepName=keepName, diff --git a/R/NMrelateOne.R b/R/NMrelateOne.R index 3270bae5..f6c83434 100644 --- a/R/NMrelateOne.R +++ b/R/NMrelateOne.R @@ -44,7 +44,7 @@ NMrelateOne <- function(file,lines,par.type="OMEGA",sections=c("PRED","PK","ERRO ,SIGMA="(SIGMA|ERR|EPS)" ) str.regex.find <- paste0("[^[:alnum:]]",str.regex) - + lines.list <- NMreadSection(lines=lines,keep.comments=FALSE) lines.list <- lines.list[names(lines.list)%in%sections] @@ -65,7 +65,11 @@ NMrelateOne <- function(file,lines,par.type="OMEGA",sections=c("PRED","PK","ERRO ## determine found variable type? - dt.code <- dt.code[,.(varname=regmatches(line2, gregexpr(paste0(str.regex.find,"\\(([0-9]+(,[0-9]+)*)\\)"),line2)) |> unlist()),by=.(line.var,line2)] + dt.code <- dt.code[,.(varname=unlist( + regmatches(line2, + gregexpr(paste0(str.regex.find,"\\(([0-9]+(,[0-9]+)*)\\)"),line2)) + )), + by=.(line.var,line2)] dt.code[,varname:=sub("^[^[:alnum:]]","",varname)] dt.code[,var.type:=sub(sprintf("(%s).*",str.regex),"\\1",varname)][,lineno:=.I] diff --git a/R/NMscanInput.R b/R/NMscanInput.R index 7110a2da..9d0ed016 100644 --- a/R/NMscanInput.R +++ b/R/NMscanInput.R @@ -101,6 +101,7 @@ NMscanInput <- function(file, formats.read, file.mod, dir.data=NULL, #### Section start: Dummy variables, only not to get NOTE's in pacakge checks #### datafile <- NULL + info <- NULL nid <- NULL input <- NULL result <- NULL @@ -167,8 +168,12 @@ NMscanInput <- function(file, formats.read, file.mod, dir.data=NULL, break } } - if(is.null(type.file)) stop("None of the allowed file formats found.") - path.data.input <- info.datafile[[paste0("path.",type.file)]] + if(is.null(type.file)){ + message(paste0("$DATA section extracted\n",info$datafile$DATA)) + message("Based on that, data files related to this file were expected:\n",info$datafile$string) + stop("None of the allowed file formats found.") + } + path.data.input <- info.datafile[[paste0("path.",type.file)]] data.input <- NMreadCsv(path.data.input,as.fun="data.table",args.fread=args.fread,args.fst=args.fst,format=type.file) diff --git a/R/NMwriteSectionOne.R b/R/NMwriteSectionOne.R index 9dfb15f7..470a11e9 100644 --- a/R/NMwriteSectionOne.R +++ b/R/NMwriteSectionOne.R @@ -63,7 +63,7 @@ NMwriteSectionOne <- function(file0,lines,section,location="replace", keep.name=TRUE,keep.comments=TRUE,as.one=TRUE, clean.spaces=FALSE) - if(length(idx.dlines)==0&location%in%cc(replace,before,after)) { + if(length(idx.dlines)==0 && location%in%cc(replace,before,after)) { if(!quiet) message("Section not found. Nothing to be done.") return(lines) } diff --git a/man/NMreadExt.Rd b/man/NMreadExt.Rd index 8a5c4db5..9ed03f19 100644 --- a/man/NMreadExt.Rd +++ b/man/NMreadExt.Rd @@ -23,7 +23,9 @@ estimates and iterations of the estimates. If \code{return="pars"} (default) the final estimates are returned in addition to what other parameter-level information is found, like FIX, sd etc. as columns. If -\code{return="iterations"}, the iterations are returned. If +\code{return="iterations"}, the iterations are returned +(including objective function value). If \code{return="obj"} +objective function value at final estimate is returned. If \code{return="all"}, all er returned, though in separate data.frames compiled in a list.} diff --git a/man/NMreadParsText.Rd b/man/NMreadParsText.Rd index 4f1ef703..b956bb51 100644 --- a/man/NMreadParsText.Rd +++ b/man/NMreadParsText.Rd @@ -111,7 +111,7 @@ $SIGMA 1 res <- NMreadParsText(lines=lines, format="\%init;[\%num];\%symbol", -format.omega="\%init \%symbol ; \%num ; \%type ; \%label ; \%unit", +format.omega="\%init; \%symbol ; \%num ; \%type ; \%label ; \%unit", field.idx="num") ## BLOCK() SAME are skipped diff --git a/man/NMreadSection.Rd b/man/NMreadSection.Rd index 48bdb876..9dfc0d9e 100644 --- a/man/NMreadSection.Rd +++ b/man/NMreadSection.Rd @@ -21,7 +21,6 @@ NMreadSection( keepName, keepComments, asOne, - cleanSpaces, ... ) @@ -79,8 +78,6 @@ probably want FALSE.} \item{asOne}{Deprecated. See as.one.} -\item{cleanSpaces}{Deprecated. See clean.spaces.} - \item{...}{Additional arguments passed to NMextractText} } \value{ diff --git a/man/mergeCheck.Rd b/man/mergeCheck.Rd index 53654456..389e977f 100644 --- a/man/mergeCheck.Rd +++ b/man/mergeCheck.Rd @@ -45,8 +45,8 @@ named like col.x and col.y in result (see ?merge). Often, this is a mistake, and the default is to throw a warning if this happens. If using mergeCheck in programming, you may want to make sure this is not happening and use -fun.commoncols=stop. If you want nothing to happen, you can do -fun.commoncols=NULL. You can also use `common.cols="drop.x"` +common.cols=stop. If you want nothing to happen, you can do +common.cols=NULL. You can also use `common.cols="drop.x"` to drop "non-by" columns in `x` with identical column names in `y`. Use "drop.y" to drop them in `y` and avoid the conflicts. The last option is to use `common.cols="merge.by"`