Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

518 invalid off diagonal eta created with piping #608

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions R/piping-ini.R
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,24 @@
# (Maybe) update parameter order; this must be at the end so that the
# parameter exists in case it is promoted from a covariate
.iniHandleAppend(expr = expr, rxui = rxui, envir = envir, append = append)

# now take out ETAs that no longer exist
.iniDf <- get("iniDf", envir=rxui)
.w <- which(is.na(.iniDf$neta1) & !is.na(.iniDf$neta2))
.reassign <- FALSE
if (length(.w) > 0) {
.iniDf <- .iniDf[-.w, ]
.reassign <- TRUE

Check warning on line 484 in R/piping-ini.R

View check run for this annotation

Codecov / codecov/patch

R/piping-ini.R#L483-L484

Added lines #L483 - L484 were not covered by tests
}
.iniDf <- get("iniDf", envir=rxui)
.w <- which(!is.na(.iniDf$neta1) & is.na(.iniDf$neta2))
if (length(.w) > 0) {
.iniDf <- .iniDf[-.w, ]
.reassign <- TRUE
}
if (.reassign) {
assign("iniDf", .iniDf, envir=rxui)
}
}

# TODO: while nlmixr2est is changed
Expand Down
44 changes: 40 additions & 4 deletions tests/testthat/test-ui-piping.R
Original file line number Diff line number Diff line change
Expand Up @@ -1921,12 +1921,12 @@ test_that("piping with append=lhs", {


test_that("test ui appending of derived variables like `sim` can work", {

one.compartment <- function() {
ini({
tka <- 0.45
tcl <- 1
tv <- 3.45
tcl <- 1
tv <- 3.45
eta.ka ~ 0.6
eta.cl ~ 0.3
eta.v ~ 0.1
Expand All @@ -1946,5 +1946,41 @@ test_that("test ui appending of derived variables like `sim` can work", {
f <- rxode2(one.compartment)

expect_error(model(f$simulationModel, sim2=sim+1, append=sim), NA)


})


test_that("off-diagonal piping issue #518", {

mod <- function() {
ini({
a <- 1
b <- 2
etaa + etab ~ c(3, 0.1, 4)
c <- 5
etac ~ 6
d <- 7
f <- 9
etad + etaf ~ c(8, 0.2, 10)
})
model({
g <- (a + etaa)/(b + etab)
h <- (c + etac)
i <- (d + etad)
j <- f + etaf
})
}

modNew <-
ini(
rxode2(mod),
etab + etac + etad ~
c(7,
0.2, 8,
0.3, 0.4, 9),
etaa ~ 0
)

expect_error(modNew$omega, NA)

})
Loading