diff --git a/NEWS.md b/NEWS.md index e5d2dd38d..718c85608 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,12 @@ ### Bug Fixes +- Previously, when compiling `mmrm` from source using a `TMB` version below 1.9.15, and installing a newer `TMB` of version 1.9.15 or above, would render the `mmrm` package unusable. This is fixed now, by checking in the dynamic library of `mmrm` whether the version of `TMB` has been sufficient. + +# mmrm 0.3.14 + +### Bug Fixes + - In version 0.3.13, when the tape optimizer from `TMB` was switched on, a warning would be given by `fit_mmrm()`, instructing users to turn off the tape optimizer. However, this is not necessary for reproducible results. Instead, it is now checked whether the deterministic hash for the `TMB` tape optimizer is used, and a warning is issued otherwise. - In version 0.3.13, the above described warning by `fit_mmrm()` was not visible to the user when calling `mmrm()` because it was caught internally, causing the first fit in each session to fail for the first tried optimizer and falling back to the other optimizers. The warning is now issued directly by `mmrm()`. This change ensures that the first model fit is consistent regarding the chosen optimizer (and thus numeric results) with subsequent model fits, avoiding discrepancies observed in version 0.3.13. diff --git a/R/utils.R b/R/utils.R index 77ee89ff6..8ef24fdba 100644 --- a/R/utils.R +++ b/R/utils.R @@ -524,6 +524,18 @@ h_drop_levels <- function(data, subject_var, visit_var, except) { data } +#' Predicate if the TMB Version Used to Compile the Package is Sufficient +#' +#' @return Flag whether the TMB version is sufficient. +#' @keywords internal +h_tmb_version_sufficient <- function() { + # Note: There is no version information saved in the dynamic library, but + # we can check like this: + tmb_config <- TMB::config(DLL = "mmrm") + tape_deterministic <- tmb_config$tmbad_deterministic_hash + !is.null(tape_deterministic) +} + #' Warn if TMB is Configured to Use Non-Deterministic Hash for Tape Optimizer #' #' This function checks the TMB configuration for the `tmbad_deterministic_hash` setting @@ -533,7 +545,7 @@ h_drop_levels <- function(data, subject_var, visit_var, except) { #' @return No return value, called for side effects. #' @keywords internal h_tmb_warn_non_deterministic <- function() { - if (utils::packageVersion("TMB") < "1.9.15") { + if (!h_tmb_version_sufficient()) { return() } tmb_config <- TMB::config(DLL = "mmrm") diff --git a/R/zzz.R b/R/zzz.R index a0e5cc9bc..ef72fa3f8 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -4,8 +4,13 @@ #' @keywords internal #' @noRd .onLoad <- function(libname, pkgname) { # nolint - if (utils::packageVersion("TMB") < "1.9.15") { - warning("TMB version 1.9.15 or higher is required for reproducible model fits", call. = FALSE) + if (!h_tmb_version_sufficient()) { + msg <- paste( + "TMB below version 1.9.15 has been used to compile the mmrm package.", + "Reproducible model fits are not guaranteed.", + "Please consider recompiling the package with TMB version 1.9.15 or higher." + ) + warning(msg, call. = FALSE) } register_on_load( diff --git a/man/h_tmb_version_sufficient.Rd b/man/h_tmb_version_sufficient.Rd new file mode 100644 index 000000000..2d84d6985 --- /dev/null +++ b/man/h_tmb_version_sufficient.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{h_tmb_version_sufficient} +\alias{h_tmb_version_sufficient} +\title{Predicate if the TMB Version Used to Compile the Package is Sufficient} +\usage{ +h_tmb_version_sufficient() +} +\value{ +Flag whether the TMB version is sufficient. +} +\description{ +Predicate if the TMB Version Used to Compile the Package is Sufficient +} +\keyword{internal} diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index cdbd82093..b9ad4dbc7 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -323,6 +323,13 @@ test_that("h_drop_levels works as expected", { ) }) +# h_tmb_version_sufficient ---- + +test_that("h_tmb_version_sufficient works as expected", { + skip_if(utils::packageVersion("TMB") < "1.9.15") + expect_true(h_tmb_version_sufficient()) +}) + # h_tmb_warn_non_deterministic ---- test_that("h_tmb_warn_non_deterministic works as expected", {