Skip to content

Commit

Permalink
support for data file names containing IGN
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelff committed Sep 6, 2024
1 parent b9b8415 commit ee9f559
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 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.7
Version: 0.1.7.901
Authors@R:
c(person(given="Philip", family="Delff",
email = "philip@delff.dk",
Expand Down
10 changes: 9 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# NMdata 0.1.8

## Bugfixes

Support for data file names including substrings "ACCEPT" and "IGN" is
added. Before, such data set file names could lead to failure if
interpreting data subsetting filters (ACCEPT and IGN(ORE)) in Nonmem
control streams.

# NMdata 0.1.7

Expand Down Expand Up @@ -104,7 +112,7 @@ of throwing an error.
* Function `NMreadShk()` to read and format `.shk` (shrinkage) files.

* Functions `mat2dt()` and `dt2mat()` included to convert between
matrices and data.frame format of matrix data - especially for
matrices and `data.frame` format of matrix data - especially for
symmetric matrices.

* Function `addOmegaCorr()` adds estimated correlation between ETAs to
Expand Down
26 changes: 20 additions & 6 deletions R/NMapplyFilters.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ NMapplyFilters <- function(data,file,text,lines,invert=FALSE,as.fun,quiet) {
value <- NULL

### Section end: Dummy variables, only not to get NOTE's in pacakge checks


if(missing(quiet)) quiet <- NULL
quiet <- NMdataDecideOption("quiet",quiet)
Expand Down Expand Up @@ -71,11 +71,19 @@ NMapplyFilters <- function(data,file,text,lines,invert=FALSE,as.fun,quiet) {
## simplifying so IGNORE/IGN is always IGN
text3 <- gsub("IGNORE","IGN",text3)

conds.sc <- regmatches(text3, gregexpr("(?:IGN) *=* *[^ (+=]",text3))

## ^(.* )* : if anything before IGN, there must be a space in between
## conds.sc <- regmatches(text3, gregexpr("^(.* )*(?:IGN) *=* *[^ (+=]",text3))
conds.sc <- regmatches(text3, gregexpr("(?<![[:alnum:]])IGN *=* *[^ (+=]",text3,perl=T))
conds.sc
conds.sc <- do.call(c,conds.sc)
### getting rid of single char conditions
text3 <- gsub(paste0("IGN"," *=* *[^ (+=]"),"",text3)


## text3 <- gsub(paste0("^(\\(.* \\)*)IGN"," *=* *[^ (+=]"),"\\1",text3)
## gsub("^((.* )*)IGN *=* *[^ (+=](.*)","\\1\\2",text3)
## gsub("((.* )*)IGN *=* *[^ (+=](.*)","\\1\\2",text3)
text3 <- gsub("(?<![[:alnum:]])IGN *=* *[^ (+=]","",perl=TRUE,text3)

## check if IGNORE or ACCEPT are found. If both found, it is an error.
any.accepts <- any(grepl("ACCEPT",text3))
any.ignores <- any(grepl("IGN",text3))
Expand All @@ -89,7 +97,7 @@ NMapplyFilters <- function(data,file,text,lines,invert=FALSE,as.fun,quiet) {
type.condition <- "ACCEPT"
}


### expression-style ones
## this is not entirely correct.
### 1. A comma-separated list of expressions can be inside the ()s.
Expand All @@ -101,6 +109,7 @@ NMapplyFilters <- function(data,file,text,lines,invert=FALSE,as.fun,quiet) {




## translating single-charaters
name.c1 <- colnames(data)[1]
scs <- sub(paste0("IGN"," *=* *(.+)"),"\\1",conds.sc)
Expand Down Expand Up @@ -165,8 +174,11 @@ NMapplyFilters <- function(data,file,text,lines,invert=FALSE,as.fun,quiet) {

cond.combine <- "|"
## remember to negate everything if the type is ignore

if(type.condition=="IGN") {
expressions.list <- paste0("!",expressions.list)
if(length(expressions.list)){
expressions.list <- paste0("!",expressions.list)
}
cond.combine <- "&"
}

Expand All @@ -175,11 +187,13 @@ NMapplyFilters <- function(data,file,text,lines,invert=FALSE,as.fun,quiet) {
} else {
conditions.all.sc <- "TRUE"
}


expressions.all <- NULL
if(length(expressions.list)) {
expressions.all <- paste0("(",paste(expressions.list,collapse=cond.combine),")")
}


if(invert) {

Expand Down

0 comments on commit ee9f559

Please sign in to comment.