diff --git a/DESCRIPTION b/DESCRIPTION index 87f65bda6..6e4cd9d26 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: bayestestR Title: Understand and Describe Bayesian Models and Posterior Distributions -Version: 0.13.1 +Version: 0.13.1.1 Authors@R: c(person(given = "Dominique", family = "Makowski", diff --git a/NEWS.md b/NEWS.md index 4ed313360..898864459 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# bayestestR 0.13.2 + +## Changes + +* Retrieving models from the environment was improved. + # bayestestR 0.13.1 ## Changes diff --git a/R/print.equivalence_test.R b/R/print.equivalence_test.R index 4929c0253..c9a522b3c 100644 --- a/R/print.equivalence_test.R +++ b/R/print.equivalence_test.R @@ -121,26 +121,36 @@ print.equivalence_test <- function(x, digits = 2, ...) { if (!is.null(obj_name)) { # first try, parent frame - model <- tryCatch( - { - get(obj_name, envir = parent.frame()) - }, - error = function(e) { - NULL - } - ) + model <- tryCatch(get(obj_name, envir = parent.frame()), error = function(e) NULL) if (is.null(model)) { # second try, global env - model <- tryCatch( - { - get(obj_name, envir = globalenv()) - }, - error = function(e) { - NULL - } - ) + model <- tryCatch(get(obj_name, envir = globalenv()), error = function(e) NULL) + } + + if (is.null(model)) { + # last try + model <- .dynGet(obj_name, ifnotfound = NULL) } } model } + + +.dynGet <- function(x, + ifnotfound = stop(gettextf("%s not found", sQuote(x)), domain = NA), + minframe = 1L, + inherits = FALSE) { + x <- insight::safe_deparse(x) + n <- sys.nframe() + myObj <- structure(list(.b = as.raw(7)), foo = 47L) + while (n > minframe) { + n <- n - 1L + env <- sys.frame(n) + r <- get0(x, envir = env, inherits = inherits, ifnotfound = myObj) + if (!identical(r, myObj)) { + return(r) + } + } + ifnotfound +}