Skip to content

Commit

Permalink
NMreadSection handling of OMEGA, OMEGAP etc
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelff committed Aug 23, 2024
1 parent 98ba597 commit 761beea
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 28 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 5 additions & 4 deletions R/NMextractText.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]*")
}


Expand Down Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions R/NMreadExt.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 12 additions & 4 deletions R/NMreadSection.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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="\\$",
Expand All @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions R/NMrelateOne.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]

Expand Down
9 changes: 7 additions & 2 deletions R/NMscanInput.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion R/NMwriteSectionOne.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion man/NMreadExt.Rd

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

2 changes: 1 addition & 1 deletion man/NMreadParsText.Rd

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

3 changes: 0 additions & 3 deletions man/NMreadSection.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/mergeCheck.Rd

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

0 comments on commit 761beea

Please sign in to comment.