Skip to content

Commit

Permalink
Merge pull request #259 from nlmixr2/255-bad-split-ui-impacts-multipl…
Browse files Browse the repository at this point in the history
…e-things-including-babelmixr2

Fix and test for non mu-referenced model
  • Loading branch information
mattfidler committed Oct 18, 2022
2 parents f948885 + 7ed01ff commit dd5409f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
11 changes: 9 additions & 2 deletions R/splitModelRxUiGet.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
}
}

.isCurEvalEncodedFunction <- function(curEval) {
if (any(curEval == c("*", "/", "^", "**", "+", "-", ""))) return(FALSE)
TRUE
}

#' This creates a mu-referenced expression block like NONMEM's PK block
#'
#' @param var Variable defined in model
Expand All @@ -110,11 +115,13 @@
} else {
stop("duplicate/missing parameter in `muRefCurEval`", call.=FALSE)
}
str2lang(paste0(var, "<-", .curEval, ifelse(.curEval == "", "", "("),
.encFun <- .isCurEvalEncodedFunction(.curEval)
str2lang(paste0(var, "<-", ifelse(.encFun, .curEval, ""),
ifelse(.encFun, "(", ""),
est,
ifelse(is.na(.low), "", paste0(",", .low)),
ifelse(is.na(.hi), "", paste0(",", .hi)),
ifelse(.curEval == "", "", ")")))
ifelse(.encFun, ")", "")))
}

#' @export
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test-split.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,26 @@ test_that("test split", {
mod <- PK_1cmt()
expect_error(mod$getSplitMuModel, NA)
})


test_that("non mu-referenced split works correctly", {
f <- function() {
ini({
tke <- 0.5
eta.ke ~ 0.04
prop.sd <- sqrt(0.1)
})
model({
ke <- tke * exp(eta.ke)
ipre <- 10 * exp(-ke * t)
f2 <- ipre / (ipre + 5)
f3 <- f2 * 3
lipre <- log(ipre)
ipre ~ prop(prop.sd)
})
}

ui <- f()

expect_error(ui$getSplitMuModel, NA)
})

0 comments on commit dd5409f

Please sign in to comment.