Skip to content

Commit

Permalink
Merge pull request #838 from nlmixr2/689-digest
Browse files Browse the repository at this point in the history
Create a rxUi method for digest
  • Loading branch information
mattfidler authored Jan 10, 2025
2 parents d456c60 + 03fbdf2 commit d572516
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: rxode2
Version: 3.0.3
Version: 3.0.3.9000
Title: Facilities for Simulating from ODE-Based Models
Authors@R: c(
person("Matthew L.","Fidler", role = c("aut", "cre"), email = "[email protected]", comment=c(ORCID="0000-0001-8538-6691")),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ S3method(rxUiGet,dvidLine)
S3method(rxUiGet,errParams)
S3method(rxUiGet,etaLhs)
S3method(rxUiGet,fun)
S3method(rxUiGet,funPartsDigest)
S3method(rxUiGet,funPrint)
S3method(rxUiGet,funTxt)
S3method(rxUiGet,ini)
Expand All @@ -229,6 +230,7 @@ S3method(rxUiGet,mvFromExpression)
S3method(rxUiGet,omega)
S3method(rxUiGet,paramsLine)
S3method(rxUiGet,props)
S3method(rxUiGet,sha1)
S3method(rxUiGet,simulationIniModel)
S3method(rxUiGet,simulationModel)
S3method(rxUiGet,simulationSigma)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# rxode2 (development version)

- Add stable hashes for rxUi objects (#838, #689)

# rxode2 3.0.3

- Add `logit`/`expit` named expressions, that is `logit(x, high=20)`
Expand Down
39 changes: 38 additions & 1 deletion R/rxUiGet.R
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,47 @@ rxUiGet.fun <- function(x, ...) {
}
attr(rxUiGet.fun, "desc") <- "Normalized model function"

#' @export
#' @rdname rxUiGet
rxUiGet.funPartsDigest <- function(x, ...) {
.ui <- x[[1]]
rxSyncOptions()
list(
normModel = .ui$mv0$model["normModel"],
iniDf = .ui$iniDf,
errLinesI = .ui$predDf$line,
errLines = vapply(.ui$predDf$line, function(l) {
deparse1(.ui$lstExpr[[l]])
}, character(1), USE.NAMES=FALSE),
# Now get environment specific differences in the model
# This changes how models can be expressed (and their output)
allow.ini=rxode2.syntax.allow.ini,
# Defined lower level functions and udf functions
definedFuns= ls(.udfEnv$symengineFs, all.names=TRUE),
# Defined rxUdfUi methods
uiFuns=as.character(utils::methods("rxUdfUi")),
# Add version of rxode2
rxVersion=rxode2::rxVersion()
)
}

#' @export
#' @rdname rxUiGet
rxUiGet.md5 <- function(x, ...) {
digest::digest(rxUiGet.funPrint(x, ...))
digest::digest(rxUiGet.funPartsDigest(x, ...), algo="md5")
}
attr(rxUiGet.md5, "desc") <- "MD5 hash of the UI model"

#' @export
#' @rdname rxUiGet
rxUiGet.sha1 <- function(x, ...) {
digest::digest(rxUiGet.funPartsDigest(x, ...), algo="sha1")
}
attr(rxUiGet.sha1, "desc") <- "SHA1 hash of the UI model"

sha1.rxUi <- function(x, digits = 14L, zapsmall = 7L, ..., algo = "sha1") {
digest::sha1(rxUiGet.funPartsDigest(list(x)),
digits=digits, zapsmall=zapsmall, ..., algo=algo)
}

#' @export
Expand Down
4 changes: 3 additions & 1 deletion R/rxode-options.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
.s3register("dplyr::rename", "rxUi")
.s3register("dplyr::rename", "function")
}

if (requireNamespace("nlme", quietly=TRUE)) {
.s3register("nlme::fixef", "rxUi")
.s3register("nlme::fixef", "function")
Expand All @@ -65,6 +64,9 @@
} else {
assignInMyNamespace(".hasUnits", FALSE)
}
if (requireNamespace("digest", quietly = TRUE)) {
.s3register("digest::sha1", "rxUi")
}
backports::import(pkgname)
## Setup rxode2.prefer.tbl
.Call(`_rxode2_setRstudio`, Sys.getenv("RSTUDIO") == "1")
Expand Down
6 changes: 6 additions & 0 deletions man/rxUiGet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d572516

Please sign in to comment.