Skip to content

Commit

Permalink
Add rxui control (and test for it too)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Nov 30, 2023
1 parent b20e5b0 commit 7dc7244
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
28 changes: 26 additions & 2 deletions R/rxsolve.R
Original file line number Diff line number Diff line change
Expand Up @@ -1146,10 +1146,33 @@ rxSolve.function <- function(object, params = NULL, events = NULL, inits = NULL,
list(theta = theta, eta = eta, envir=envir)))
}

.uiRxControl <- function(ui, params = NULL, events = NULL, inits = NULL, ...,
theta = NULL, eta = NULL) {
.ctl <- rxControl()
.meta <- get("meta", ui)
.lst <- list(...)
.nlst <- names(.lst)
.w <- which(vapply(names(.ctl), function(x) {
!(x %in% names(.nlst)) && exists(x, envir=.meta)
}, logical(1), USE.NAMES=FALSE))
.extra <- NULL
if (length(.w) > 0) {
.v <- names(.ctl)[.w]
.minfo(paste0("rxControl items read from fun: '",
paste(.v, collapse="', '"), "'"))
.extra <- setNames(lapply(.v, function(x) {
get(x, envir=.meta)
}), .v)
}
do.call(rxSolve, c(list(NULL, params = NULL, events = NULL, inits = NULL),
.lst, .extra,
list(theta=theta, eta=eta)))
}

.rxSolveFromUi <- function(object, params = NULL, events = NULL, inits = NULL, ...,
theta = NULL, eta = NULL) {
.rxControl <- rxSolve(NULL, params = params, events = events, inits = inits, ...,
theta = theta, eta = eta)
.rxControl <- .uiRxControl(object, params = params, events = events, inits = inits, ...,
theta = theta, eta=eta)
if (rxIs(params, "rx.event")) {
if (!is.null(events)) {
.tmp <- events
Expand Down Expand Up @@ -2065,6 +2088,7 @@ odeMethodToInt <- function(method = c("liblsoda", "lsoda", "dop853", "indLin"))
}



#' This updates the tolerances based on the sensitivity equations
#'
#' This assumes the normal ODE equations are the first equations and
Expand Down
48 changes: 48 additions & 0 deletions tests/testthat/test-rxui-ctl.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
rxTest({
test_that("get information from rxUi", {

## Test mixed solved and ODEs
mod2 <- function() {
sigma <- lotri({
err1 ~ 0.05
err2 ~ 0.05
})
ini({
KA = 2.94E-01
TCL = 1.86E+01
V2 = 4.02E+01
Q = 1.05E+01
V3 = 2.97E+02
Kin = 1
Kout = 1
EC50 = 200
eta.Cl ~ 0.2
})
model({
## the order of variables do not matter, the type of compartmental
## model is determined by the parameters specified.
CL <- TCL * exp(eta.Cl)
C2 <- linCmt(KA, CL, V2, Q, V3)
eff(0) <- 1 ## This specifies that the effect compartment starts at 1.
d/dt(eff) <- Kin - Kout * (1 - C2 / (EC50 + C2)) * eff
##
resp <- eff + err1
pk <- C2 * exp(err2)
})
}

f <- mod2()

ev <- eventTable() %>%
add.dosing(dose = 10000, nbr.doses = 10, dosing.interval = 12, dosing.to = 2) %>%
add.dosing(dose = 20000, nbr.doses = 5, start.time = 120, dosing.interval = 24, dosing.to = 2) %>%
add.sampling(0:240)

ev <- ev %>% et(0.5, evid = 2)

pk4 <- rxSolve(f, events=ev, nSub=4, cores = 1, addDosing = TRUE)
expect_true(inherits(pk4, "rxSolve"))

})

})

0 comments on commit 7dc7244

Please sign in to comment.