Skip to content

Commit

Permalink
Merge pull request #23 from nlmixr2/22-ignore-line
Browse files Browse the repository at this point in the history
Add ignoreline to content parser
  • Loading branch information
mattfidler authored Nov 28, 2024
2 parents 1349c50 + f2a33f4 commit b5d1723
Show file tree
Hide file tree
Showing 9 changed files with 2,604 additions and 2,203 deletions.
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.0.2
Date: 2024-09-20 17:23:09 UTC
SHA: 50a6d133e91e263750f7208c21c5cfc094ff5d07
Version: 0.0.3
Date: 2024-10-24 03:47:22 UTC
SHA: 01ef6508874c5a3dd198fba94580c8014fc3ea4c
2 changes: 2 additions & 0 deletions R/content.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
cont=.monolix2rx$contLst,
cat=.monolix2rx$catLst2,
reg=.monolix2rx$regLst,
ignore=.monolix2rx$ignoreLst,
nbdoses=.monolix2rx$ssNbdoses,
yname=.monolix2rx$yname,
ynameQuote=.monolix2rx$ynameQuote,
Expand Down Expand Up @@ -186,6 +187,7 @@ as.character.monolix2rxContent <- function(x, ...) {
}, character(1), USE.NAMES = FALSE)
c(.cur[!is.na(.cur)],
.asCharacterReg(x),
.asCharacterIgnore(x),
vapply(x$cont, function(n) {
paste0(n, " = {use=covariate, type=continuous}")
}, character(1), USE.NAMES = FALSE),
Expand Down
25 changes: 25 additions & 0 deletions R/ind.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
.fileinfoIni()
.monolix2rx$inpLst <- character(0)
.monolix2rx$regLst <- character(0)
.monolix2rx$ignoreLst <- character(0)
.monolix2rx$catLst2 <- NULL
.monolix2rx$ind <- NULL
}
Expand Down Expand Up @@ -90,6 +91,7 @@
.ind <- list(input=.monolix2rx$inpLst,
cat=.monolix2rx$catLst2,
reg=.monolix2rx$regLst,
ignore=.monolix2rx$ignoreLst,
file=.monolix2rx$file)
class(.ind) <- "monolix2rxInd"
.indIni(full=TRUE)
Expand All @@ -110,6 +112,15 @@
# What does that mean?
.monolix2rx$regLst <- c(.monolix2rx$regLst, reg)
}
#' Flag a column as ignored
#'
#' @param ignore column to ignore
#' @return nothing, called for side effect
#' @noRd
#' @author Matthew L. Fidler
.indIgnore <- function(ignore) {
.monolix2rx$ignoreLst <- c(.monolix2rx$ignoreLst, ignore)
}

#' As.character for regressor items
#'
Expand All @@ -124,6 +135,19 @@
paste0(n, " = {use = regressor}")
}, character(1), USE.NAMES = FALSE)
}
#' Change expression to ignored line
#'
#' @param x line to ignore
#' @return character vector representing ignored variables
#' @author Matthew L. Fidler
#' @noRd
.asCharacterIgnore <- function(x) {
if (length(x$ignore) == 0L) return(character(0))
vapply(x$ignore,
function(n) {
paste0(n, " = {use = ignoredline}")
}, character(1), USE.NAMES = FALSE)
}

#' as.character for the categorical variables in `$cat`
#'
Expand Down Expand Up @@ -173,6 +197,7 @@ as.character.monolix2rxInd <- function(x, ...) {
}
.ret <- c(.ret, .asCharacterReg(x))
.ret <- c(.ret, .asCharacterCat(x))
.ret <- c(.ret, .asCharacterIgnore(x))
c(.ret, .asCharacterFile(x))
}

Expand Down
3 changes: 2 additions & 1 deletion inst/mlxtranContent.g
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ssLine: identifier '=' '{' 'use' '=' ('steadystate' | 'steadyState' ) (',' 'nbdo
regressorLine: identifier '=' '{' 'use' '=' 'regressor' '}';
contLine: identifier '=' '{' 'use' '=' 'covariate' ',' 'type' '=' 'continuous' '}';
catLine: identifier '=' '{' 'use' '=' 'covariate' ',' 'type' '=' 'categorical' '}';

ignoreLine: identifier '=' '{' 'use' '=' ('ignore' | 'ignoreLine' | 'ignoreline' | 'ignored' | 'ignoredLine' | 'ignoredline') '}';
ytypeType: char_t1 | char_t2 | identifier | number;
ytypeOp1: 'ytype' '=' ytypeType;
ytypeOp2: 'ytype' '=' '{' ytypeType (',' ytypeType)* '}';
Expand Down Expand Up @@ -69,6 +69,7 @@ statement: idLine singleLineComment?
| durLine singleLineComment?
| mdvLine singleLineComment?
| ssLine singleLineComment?
| ignoreLine singleLineComment?
| regressorLine singleLineComment?
| contLine singleLineComment?
| catLine singleLineComment?
Expand Down
2 changes: 2 additions & 0 deletions src/mlxtranContent.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ extern sbuf curLine;
int individual_process_catCov(const char *name, D_ParseNode *pn, int i);
int individual_process_catId(const char *name, D_ParseNode *pn);
int individual_process_regressor(const char *name, D_ParseNode *pn);
int individual_process_ignore(const char *name, D_ParseNode *pn);

int content_process_identifier(const char *name, D_ParseNode *pn) {
if (!strcmp(name, "idLine")) {
Expand Down Expand Up @@ -318,6 +319,7 @@ void wprint_parsetree_content(D_ParserTables pt, D_ParseNode *pn, int depth, pri
int nch = d_get_number_of_children(pn);
if (individual_process_catId(name, pn) ||
individual_process_regressor(name, pn) ||
individual_process_ignore(name, pn) ||
content_process_identifier(name, pn) ||
content_process_time(name, pn) ||
content_process_evid(name, pn) ||
Expand Down
4,707 changes: 2,509 additions & 2,198 deletions src/mlxtranContent.g.d_parser.h

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion src/mlxtranInd.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ int individual_process_regressor(const char *name, D_ParseNode *pn) {
return 0;
}

int individual_process_ignore(const char *name, D_ParseNode *pn) {
if (!strcmp("ignoreLine", name)) {
D_ParseNode *xpn = d_get_child(pn, 0);
char *v = (char*)rc_dup_str(xpn->start_loc.s, xpn->end);
monolix2rxSingle(v, ".indIgnore");
return 1;
}
return 0;
}


void wprint_parsetree_individual(D_ParserTables pt, D_ParseNode *pn, int depth, print_node_fn_t fn, void *client_data) {
char *name = (char*)pt.symbols[pn->symbol].name;
int nch = d_get_number_of_children(pn);
Expand All @@ -130,7 +141,8 @@ void wprint_parsetree_individual(D_ParserTables pt, D_ParseNode *pn, int depth,
return;
} else if (individual_process_catId(name, pn) ||
individual_process_inpId(name, pn) ||
individual_process_regressor(name, pn)) {
individual_process_regressor(name, pn) ||
individual_process_ignore(name, pn)) {
// return early; no need to process more
return;
}
Expand Down
46 changes: 46 additions & 0 deletions tests/testthat/test-content.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Sex = {type=categorical, categories={M, F}}")
Sex = list(cat = c("M", "F"),
quote = c(FALSE, FALSE))),
reg = c("E0", "Emax"),
ignore = character(0),
nbdoses = 7L,
yname = c("1", "2"),
ynameQuote=c(TRUE, TRUE),
Expand Down Expand Up @@ -80,6 +81,7 @@ limit = {use=limit}")
Sex = list(cat = c("M", "F"),
quote = c(FALSE, FALSE))),
reg = c("E0", "Emax"),
ignore=character(0),
nbdoses = 10L,
yname = c("1", "2"),
ynameQuote=c(TRUE, TRUE),
Expand Down Expand Up @@ -163,3 +165,47 @@ test_that("dur", {
expect_equal(as.character(.content("dur = {use=infusiontime}")),
"dur = {use=infusiontime}")
})

test_that("content ignore", {

tmp <- .content("ID = {use=identifier}
TIME = {use=time}
EVID = {use=eventidentifier}
AMT = {use=amount}
DV = {use=observation, name={y1, y2}, yname={'1', '2'}, type={continuous, event}}
ADM = {use=administration}
YTYPE = {use=observationtype}
WT={use=covariate, type=continuous}
CRCL={use=covariate, type=continuous}
E0 = {use = regressor}
Emax = {use = regressor}
Race = {type=categorical, categories={Caucasian, Black, Latin}}
Sex = {type=categorical, categories={M, F}}
FLAG = {use=ignoredline}")


tmp2 <- list(use1 = c(identifier = "ID", time = "TIME", eventidentifier = "EVID",
amount = "AMT", interdoseinterval = NA, censored = NA,
limit = NA, observationtype = "YTYPE", administration = "ADM",
steadystate = NA, observation = "DV", occasion = NA,
rate = NA, additionaldose = NA, missingdependentvariable = NA,
infusiontime = NA),
cont = c("WT", "CRCL"),
cat = list(Race = list(cat = c("Caucasian", "Black", "Latin"),
quote = c(FALSE, FALSE, FALSE)),
Sex = list(cat = c("M", "F"),
quote = c(FALSE, FALSE))),
reg = c("E0", "Emax"),
ignore = "FLAG",
nbdoses = 7L,
yname = c("1", "2"),
ynameQuote = c(TRUE, TRUE),
ytype = character(0),
ytypeQuote = logical(0),
name = c("y1", "y2"),
type = c("continuous", "event"))

class(tmp2) <- "monolix2rxContent"

expect_equal(tmp, tmp2)
})
2 changes: 2 additions & 0 deletions tests/testthat/test-ind.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Sex = {type=categorical, categories={M, F}}")
Sex = list(cat = c("M", "F"),
quote = c(FALSE, FALSE))),
reg = "E0",
ignore = character(0),
file=character(0))
class(.tmp2) <- "monolix2rxInd"

Expand All @@ -34,6 +35,7 @@ SEX = {type=categorical, categories={Female, Male}}")
SEX = list(cat = c("Female", "Male"),
quote = c(FALSE, FALSE))),
reg = character(0),
ignore = character(0),
file=character(0))
class(.tmp2) <- "monolix2rxInd"
expect_equal(.tmp, .tmp2)
Expand Down

0 comments on commit b5d1723

Please sign in to comment.