From 47cb2a38be61a9c13622053db1bbf5113e92cb52 Mon Sep 17 00:00:00 2001 From: "Matthew L. Fidler" Date: Sun, 4 Aug 2024 18:53:38 -0500 Subject: [PATCH] Clean up nonmem and test nonmem runCommand=NA --- R/nonmemNlmixr2est.R | 8 +++--- tests/testthat/test-nonmem.R | 52 +++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/R/nonmemNlmixr2est.R b/R/nonmemNlmixr2est.R index ca9cb3c7..09913b80 100644 --- a/R/nonmemNlmixr2est.R +++ b/R/nonmemNlmixr2est.R @@ -207,14 +207,12 @@ quote=FALSE) .minfo("done") } - if (!rxode2::rxGetControl(.ui, "run", TRUE)) { + .cmd <- rxode2::rxGetControl(.ui, "runCommand", "") + if (!rxode2::rxGetControl(.ui, "run", TRUE) || + is.na(.cmd)) { .minfo("only exported NONMEM control stream/data") return(invisible()) } - if (is.na(rxode2::rxGetControl(.ui, "runCommand", ""))) { - .minfo("not running NONMEM") - return(.ui) - } if (!file.exists(file.path(.exportPath, .ui$nonmemXml))) { print(file.path(.exportPath, .ui$nonmemXml)) .nonmemRunner(ui=.ui) diff --git a/tests/testthat/test-nonmem.R b/tests/testthat/test-nonmem.R index d5f5d29b..9781dae9 100644 --- a/tests/testthat/test-nonmem.R +++ b/tests/testthat/test-nonmem.R @@ -600,13 +600,13 @@ withr::with_tempdir({ d/dt(A_tr2) = KTR * A_tr1 - KTR * A_tr2; d/dt(A_tr3) = KTR * A_tr2 - KTR * A_tr3; d/dt(A_circ) = KTR * A_tr3 - KTR * A_circ; - + CIRC ~ prop(prop.err) }) } - + w <- wbc() - + expect_equal( w$nonmemErrF, paste(c( @@ -761,3 +761,49 @@ withr::with_tempdir({ }) }) }) + + +test_that("nonmem model creation without running", { + withr::with_tempdir({ + + one.cmt <- function() { + ini({ + tka <- 0.45 ; label("Ka") + tcl <- log(c(0, 2.7, 100)) ; label("Log Cl") + tv <- 3.45; label("log V") + cl.wt <- 0 + v.wt <- 0 + eta.ka ~ 0.6 + eta.cl ~ 0.3 + eta.v ~ 0.1 + add.sd <- 0.7 + }) + model({ + ka <- exp(tka + eta.ka) + cl <- exp(tcl + eta.cl + WT * cl.wt) + v <- exp(tv + eta.v)+ WT ^ 2 * v.wt + d/dt(depot) <- -depot*ka + d/dt(central) <- depot*ka - cl*central/v + cp <-central/v + cp ~ add(add.sd) + }) + } + + files <- c("nonmemTest.csv", "nonmemTest.md5", "nonmemTest.nmctl") + + nlmixr2(one.cmt, nlmixr2data::theo_sd, "nonmem", + nonmemControl(runCommand=NA, modelName="nonmemTest")) + + lapply(files, function(f) { expect_true(file.exists(file.path("nonmemTest-nonmem", f))) }) + + nlmixr2(one.cmt, nlmixr2data::theo_sd, "nonmem", + nonmemControl(runCommand=NA, modelName="nonmemTest")) + + lapply(files, function(f) { + expect_true(file.exists(file.path("nonmemTest-nonmem", f))) + unlink(file.path("nonmemTest-nonmem", f)) + }) + unlink("nonmemTest-nonmem", recursive = TRUE) + + }) +})