Skip to content

Commit

Permalink
Merge branch 'main' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Sep 15, 2024
2 parents 24d3a96 + dbc95d2 commit df7d941
Show file tree
Hide file tree
Showing 38 changed files with 3,421 additions and 375 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ jobs:
pak-version: stable
extra-packages: |
any::rcmdcheck
nlmixr2/n1qn1c
nlmixr2/lbfgsb3c
nlmixr2/PreciseSums
nlmixr2/dparser-R
nlmixr2/lotri
nlmixr2/rxode2ll
nlmixr2/rxode2parse
nlmixr2/rxode2random
nlmixr2/rxode2et
nlmixr2/rxode2
nlmixr2/nlmixr2est
nlmixr2/nlmixr2extra
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ jobs:
with:
extra-packages: |
any::pkgdown
any::mrgsolve
any::PKPDsim
nlmixr2/n1qn1c
nlmixr2/lbfgsb3c
nlmixr2/PreciseSums
nlmixr2/lotri
nlmixr2/dparser-R
nlmixr2/rxode2ll
nlmixr2/rxode2parse
nlmixr2/rxode2random
nlmixr2/rxode2et
nlmixr2/rxode2
nlmixr2/nonmem2rx
nlmixr2/nlmixr2est
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ jobs:
pak-version: devel
extra-packages: |
any::covr
nlmixr2/n1qn1c
nlmixr2/lbfgsb3c
nlmixr2/PreciseSums
nlmixr2/dparser-R
nlmixr2/lotri
nlmixr2/rxode2ll
nlmixr2/rxode2parse
nlmixr2/rxode2random
nlmixr2/rxode2et
nlmixr2/rxode2
nlmixr2/nlmixr2est
nlmixr2/nlmixr2extra
Expand Down
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: babelmixr2
Type: Package
Title: Use 'nlmixr2' to Interact with Open Source and Commercial Software
Version: 0.1.2
Version: 0.1.3
Authors@R: c(person("Matthew","Fidler", role = c("aut", "cre"), email = "[email protected]", comment=c(ORCID="0000-0001-8538-6691")),
person("Bill", "Denney", email="[email protected]", role="aut", comment=c(ORCID="0000-0002-5759-428X")),
person("Nook", "Fulloption", role="ctb", comment="goldfish art"))
Expand All @@ -26,7 +26,9 @@ Suggests:
rmarkdown,
spelling,
PopED,
units
units,
vdiffr,
dplyr
Depends:
R (>= 3.5),
nlmixr2 (>= 2.0.8)
Expand All @@ -41,10 +43,10 @@ Imports:
qs,
rex,
rxode2
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
Config/testthat/edition: 3
LinkingTo:
Rcpp, rxode2, RcppArmadillo, RcppEigen, rxode2parse
Rcpp, rxode2, RcppArmadillo, RcppEigen
Language: en-US
VignetteBuilder: knitr
12 changes: 12 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ S3method(nmObjGetControl,nonmem2rx)
S3method(nmObjGetFoceiControl,monolix)
S3method(nmObjHandleControlObject,monolixControl)
S3method(nmObjHandleControlObject,nonmemControl)
S3method(print,babelmixr2popedScript)
S3method(print,pkncaEst)
S3method(rxUiGet,mlxtran)
S3method(rxUiGet,mlxtranDatafile)
Expand Down Expand Up @@ -119,18 +120,28 @@ S3method(rxUiGet,popedCovd)
S3method(rxUiGet,popedD)
S3method(rxUiGet,popedFErrorFun)
S3method(rxUiGet,popedFfFun)
S3method(rxUiGet,popedFfFunScript)
S3method(rxUiGet,popedFgFun)
S3method(rxUiGet,popedFullRxModel)
S3method(rxUiGet,popedGetEventFun)
S3method(rxUiGet,popedNotfixedBpop)
S3method(rxUiGet,popedNotfixedCovd)
S3method(rxUiGet,popedNotfixedD)
S3method(rxUiGet,popedNotfixedSigma)
S3method(rxUiGet,popedParameters)
S3method(rxUiGet,popedRxmodelBase)
S3method(rxUiGet,popedScriptBeforeCtl)
S3method(rxUiGet,popedSettings)
S3method(rxUiGet,popedSigma)
export(.minfo)
export(.popedF)
export(.popedFree)
export(.popedRxRunSetup)
export(.popedSetup)
export(.popedSolveIdME)
export(.popedSolveIdME2)
export(.popedSolveIdN)
export(.popedSolveIdN2)
export(.popedW)
export(as.nlmixr)
export(as.nlmixr2)
Expand Down Expand Up @@ -171,6 +182,7 @@ importFrom(nlmixr2est,nmObjHandleControlObject)
importFrom(nonmem2rx,as.nonmem2rx)
importFrom(nonmem2rx,nonmem2rx)
importFrom(rxode2,.minfo)
importFrom(rxode2,`model<-`)
importFrom(rxode2,rxModelVars)
importFrom(rxode2,rxUiGet)
importFrom(stats,na.omit)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# babelmixr2 0.1.3

* Changed default NONMEM rounding protection to FALSE

* Added a `run` option to the `monolixControl()` and `nonemControl()`
in case you only want to export the modeling files and not run the
models.

# babelmixr2 0.1.2

* Handle algebraic `mu` expressions
Expand Down
24 changes: 24 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ convertDataBack <- function(id, time, amt, ii, evid, cmt, cmtDvid, dvidDvid, lin
.Call(`_babelmixr2_convertDataBack`, id, time, amt, ii, evid, cmt, cmtDvid, dvidDvid, linNcmt, linKa, neq, replaceEvid, zeroDose2)
}

popedFree <- function() {
.Call(`_babelmixr2_popedFree`)
}

popedSetup <- function(e, full) {
.Call(`_babelmixr2_popedSetup`, e, full)
}

popedSolveIdN2 <- function(theta, mt, iid, totn) {
.Call(`_babelmixr2_popedSolveIdN2`, theta, mt, iid, totn)
}

popedSolveIdN <- function(theta, mt, iid, totn) {
.Call(`_babelmixr2_popedSolveIdN`, theta, mt, iid, totn)
}

popedSolveIdME <- function(theta, umt, mt, ms, nend, id, totn) {
.Call(`_babelmixr2_popedSolveIdME`, theta, umt, mt, ms, nend, id, totn)
}

popedSolveIdME2 <- function(theta, umt, mt, ms, nend, id, totn) {
.Call(`_babelmixr2_popedSolveIdME2`, theta, umt, mt, ms, nend, id, totn)
}

transDv <- function(inDv, inCmt, cmtTrans, lambda, yj, low, high) {
.Call(`_babelmixr2_transDv`, inDv, inCmt, cmtTrans, lambda, yj, low, high)
}
Expand Down
8 changes: 7 additions & 1 deletion R/monolixControl.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#' monolix. See details for function usage.
#' @param absolutePath Boolean indicating if the absolute path should
#' be used for the monolix runs
#'
#' @param run Should monolix be run and the results be imported to nlmixr2? (Default is TRUE)
#' @inheritParams nonmemControl
#' @inheritParams nlmixr2est::saemControl
#' @return A monolix control object
Expand Down Expand Up @@ -66,6 +68,7 @@
#' @importFrom methods is
#' @importFrom stats na.omit setNames
#' @importFrom utils assignInMyNamespace read.csv write.csv
#' @importFrom rxode2 `model<-`
monolixControl <- function(nbSSDoses=7,
useLinearization=FALSE,
stiff=FALSE,
Expand All @@ -92,6 +95,7 @@ monolixControl <- function(nbSSDoses=7,
absolutePath=FALSE,
modelName=NULL,
muRefCovAlg=TRUE,
run=TRUE,
...) {
checkmate::assertLogical(stiff, max.len=1, any.missing=FALSE)
checkmate::assertLogical(exploratoryAutoStop, max.len=1, any.missing=FALSE)
Expand All @@ -109,6 +113,7 @@ monolixControl <- function(nbSSDoses=7,
checkmate::assertNumeric(exploratoryAlpha, lower=0.0, upper=1.0)
checkmate::assertNumeric(omegaTau, lower=0.0, upper=1.0)
checkmate::assertNumeric(errorModelTau, lower=0.0, upper=1.0)
checkmate::assertLogical(run, len=1, any.missing=FALSE)

if (!is.null(modelName)) {
checkmate::assertCharacter(modelName, len=1, any.missing=FALSE)
Expand Down Expand Up @@ -197,7 +202,8 @@ monolixControl <- function(nbSSDoses=7,
genRxControl=genRxControl,
useLinearization=useLinearization,
modelName=modelName,
muRefCovAlg=muRefCovAlg)
muRefCovAlg=muRefCovAlg,
run=run)
class(.ret) <- "monolixControl"
.ret
}
Expand Down
18 changes: 16 additions & 2 deletions R/monolixNlmixr2est.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -231,7 +234,8 @@
.mlxtran <- .ui$monolixMlxtranFile
.runLock <- .ui$monolixRunLock

if (checkmate::testFileExists(.qs)) {
.cmd <- rxode2::rxGetControl(.ui, "runCommand", "")
if (checkmate::testFileExists(.qs)) {
.minfo("load saved nlmixr2 object")
.ret <- qs::qread(.qs)
if (!exists("parHistData", .ret$env)) {
Expand All @@ -253,10 +257,16 @@
writeLines(text=.hashMd5, con=.hashFile)
write.csv(.dataDf, file=.csv, na = ".", row.names = FALSE)
.minfo("done")
if (!rxode2::rxGetControl(.ui, "run", TRUE)) {
.minfo("only exported Monolix mlxtran, txt model and data")
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)
Expand All @@ -278,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)) {
Expand Down
22 changes: 15 additions & 7 deletions R/nonmemControl.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
#' @param tol NONMEM tolerance for ODE solving advan
#' @param atol NONMEM absolute tolerance for ODE solving
#' @param sstol NONMEM tolerance for steady state ODE solving
#' @param ssatol NONMEM absolute tolerance for steady state ODE solving
#' @param ssatol NONMEM absolute tolerance for steady state ODE
#' solving
#' @param sigl NONMEM sigl estimation option
#' @param sigdig the significant digits for NONMEM
#' @param print The print number for NONMEM
#' @param extension NONMEM file extensions
#' @param outputExtension Extension to use for the NONMEM output
#' listing
#' @param runCommand Command to run NONMEM (typically the path to "nmfe75") or a
#' function. See the details for more information.
#' @param runCommand Command to run NONMEM (typically the path to
#' "nmfe75") or a function. See the details for more information.
#' @param iniSigDig How many significant digits are printed in $THETA
#' and $OMEGA when the estimate is zero. Also controls the zero
#' protection numbers
Expand All @@ -45,14 +46,15 @@
#' simulations
#' @param mapiter the number of map iterations for IMP method
#' @param niter number of iterations in NONMEM estimation methods
#' @param isample Isample argument for NONMEM ITS estimation method
#' @param isample Isample argument for NONMEM ITS estimation method
#' @param iaccept Iaccept for NONMEM ITS estimation methods
#' @param iscaleMin parameter for IMP NONMEM method (ISCALE_MIN)
#' @param iscaleMax parameter for IMP NONMEM method (ISCALE_MAX)
#' @param df degrees of freedom for IMP method
#' @param seed is the seed for NONMEM methods
#' @param mapinter is the MAPINTER parameter for the IMP method
#' @param addProp,sumProd,optExpression,calcTables,compress,ci,sigdigTable
#' @param
#' addProp,sumProd,optExpression,calcTables,compress,ci,sigdigTable
#' Passed to \code{nlmixr2est::foceiControl}
#' @param readRounding Try to read NONMEM output when NONMEM
#' terminated due to rounding errors
Expand All @@ -62,6 +64,9 @@
#' @param modelName Model name used to generate the NONMEM output. If
#' `NULL` try to infer from the model name (could be `x` if not
#' clear). Otherwise use this character for outputs.
#' @param run Should NONMEM be run (and the files imported to
#' nlmixr2); default is TRUE, but FALSE will simply create the
#' NONMEM control stream and data file.
#' @param ... optional \code{genRxControl} argument controlling
#' automatic \code{rxControl} generation.
#'
Expand Down Expand Up @@ -93,7 +98,7 @@ nonmemControl <- function(est=c("focei", "imp", "its", "posthoc"),
outputExtension=getOption("babelmixr2.nmOutputExtension", ".lst"),
runCommand=getOption("babelmixr2.nonmem", ""),
iniSigDig=5,
protectZeros=TRUE,
protectZeros=FALSE,
muRef=TRUE,
addProp = c("combined2", "combined1"),
rxControl=NULL,
Expand All @@ -117,6 +122,7 @@ nonmemControl <- function(est=c("focei", "imp", "its", "posthoc"),
noabort=TRUE,
modelName=NULL,
muRefCovAlg=TRUE,
run=TRUE,
...) {
# nonmem manual slides suggest tol=6, sigl=6 sigdig=2
checkmate::assertIntegerish(maxeval, lower=100, len=1, any.missing=FALSE)
Expand All @@ -142,6 +148,7 @@ nonmemControl <- function(est=c("focei", "imp", "its", "posthoc"),
checkmate::assertIntegerish(seed, lower=1, len=1, any.missing=FALSE)
checkmate::assertIntegerish(mapiter, len=1, any.missing=FALSE)
checkmate::assertLogical(muRefCovAlg, any.missing=FALSE, len=1)
checkmate::assertLogical(run, any.missing=FALSE, len=1)
if (!is.null(modelName)) {
checkmate::assertCharacter(modelName, len=1, any.missing=FALSE)
}
Expand Down Expand Up @@ -240,7 +247,8 @@ nonmemControl <- function(est=c("focei", "imp", "its", "posthoc"),
seed=seed,
mapiter=mapiter,
modelName=modelName,
muRefCovAlg=muRefCovAlg
muRefCovAlg=muRefCovAlg,
run=run
)
class(.ret) <- "nonmemControl"
.ret
Expand Down
12 changes: 7 additions & 5 deletions R/nonmemNlmixr2est.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,11 @@
quote=FALSE)
.minfo("done")
}
if (is.na(rxode2::rxGetControl(.ui, "runCommand", ""))) {
.minfo("not running NONMEM")
return(.ui)
.cmd <- rxode2::rxGetControl(.ui, "runCommand", "")
if (!rxode2::rxGetControl(.ui, "run", TRUE) ||
is.na(.cmd)) {
.minfo("only exported NONMEM control stream/data")
return(invisible(.ui))
}
if (!file.exists(file.path(.exportPath, .ui$nonmemXml))) {
print(file.path(.exportPath, .ui$nonmemXml))
Expand Down Expand Up @@ -262,11 +264,11 @@
assign("message", paste(.msg$message, collapse="\n "), envir=.ret$env)
qs::qsave(.ret, .qs)
}
return(.ret)
.ret
}

#' Run NONMEM using either the user-specified command or function
#'
#'
#' @param ui The nlmixr2 UI object for running
#' @param monolix are we actually running monolix
#' @return NULL
Expand Down
Loading

0 comments on commit df7d941

Please sign in to comment.