diff --git a/R/monolixNlmixr2est.R b/R/monolixNlmixr2est.R index 3fb53cdd..83a0fe12 100644 --- a/R/monolixNlmixr2est.R +++ b/R/monolixNlmixr2est.R @@ -137,6 +137,9 @@ cmd <- rxode2::rxGetControl(ui, "runCommand", "") if (is.character(cmd)) { cmd <- .monolixRunCommand + } else if (is.na(cmd)) { + .minfo("run Monolix manually and rerun nlmixr()") + return(NULL) } else if (!is.function(cmd)) { stop("invalid value for monolixControl(runCommand=)", call.=FALSE) @@ -231,6 +234,7 @@ .mlxtran <- .ui$monolixMlxtranFile .runLock <- .ui$monolixRunLock + .cmd <- rxode2::rxGetControl(.ui, "runCommand", "") if (file.exists(.qs)) { .minfo("load saved nlmixr2 object") .ret <- qs::qread(.qs) @@ -258,9 +262,11 @@ return(invisible()) } .runLS <- FALSE - .cmd <- rxode2::rxGetControl(.ui, "runCommand", "") if (!identical(.cmd, "")) { .monolixRunner(ui=.ui) + if (is.na(.cmd)) { + return(invisible()) + } } else { if (.hasLixoftConnectors()) { .x <- try(lixoftConnectors::loadProject(.mlxtran), silent=TRUE) @@ -282,6 +288,10 @@ } } } else { + if (is.na(.cmd)) { + .minfo(paste0("leaving alone monolix files because '", .model, "' is present")) + return(invisible()) + } .minfo(paste0("assuming monolix is running because '", .model, "' is present")) } if (!dir.exists(.exportPath)) { diff --git a/R/nonmemNlmixr2est.R b/R/nonmemNlmixr2est.R index ca9cb3c7..507de0e9 100644 --- a/R/nonmemNlmixr2est.R +++ b/R/nonmemNlmixr2est.R @@ -207,13 +207,11 @@ 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) + return(invisible(.ui)) } if (!file.exists(file.path(.exportPath, .ui$nonmemXml))) { print(file.path(.exportPath, .ui$nonmemXml)) diff --git a/tests/testthat/test-monolix.R b/tests/testthat/test-monolix.R index 0408d243..4cdfa5cd 100644 --- a/tests/testthat/test-monolix.R +++ b/tests/testthat/test-monolix.R @@ -85,7 +85,7 @@ if (FALSE) { low=NA_real_, hi=NA_real_)), NULL) }) - + } @@ -267,3 +267,47 @@ test_that("monolix dsl", { .ee(.rxToM("add.sd"), "add__sd") }) + +test_that("monolix 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("monolixTest-monolix.csv", "monolixTest-monolix.mlxtran", + "monolixTest-monolix.md5", "monolixTest-monolix.txt") + + nlmixr2(one.cmt, nlmixr2data::theo_sd, "monolix", + monolixControl(runCommand=NA, modelName="monolixTest")) + + lapply(files, function(f) { expect_true(file.exists(f)) }) + + nlmixr2(one.cmt, nlmixr2data::theo_sd, "monolix", + monolixControl(runCommand=NA, modelName="monolixTest")) + lapply(files, function(f) { + expect_true(file.exists(f)) + unlink(f) + }) + + }) +}) diff --git a/tests/testthat/test-nonmem.R b/tests/testthat/test-nonmem.R index d5f5d29b..fe430e6b 100644 --- a/tests/testthat/test-nonmem.R +++ b/tests/testthat/test-nonmem.R @@ -125,6 +125,7 @@ withr::with_tempdir({ }) test_that("NONMEM dsl, full model", { + one.cmt <- function() { ini({ tka <- 0.45 ; label("Ka") @@ -145,16 +146,18 @@ withr::with_tempdir({ cp ~ add(add.sd) }) } + expect_message( - ui <- nlmixr( one.cmt, data=nlmixr2data::Oral_1CPT, est="nonmem", control=nonmemControl(runCommand=NA) ), - regexp="not running NONMEM" + regexp="only exported NONMEM" ) + expect_s3_class(ui, "rxUi") expect_type(ui$nonmemModel, "character") + expect_equal( ui$nonmemModel, paste( @@ -223,6 +226,7 @@ withr::with_tempdir({ collapse="\n" ) ) + }) # pk.turnover.emax3 <- function() { @@ -600,13 +604,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 +765,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) + + }) +})