Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jun 1, 2023
1 parent 035da1e commit 798f2e7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# bayestestR 0.13.2

## Changes

* Retrieving models from the environment was improved.

# bayestestR 0.13.1

## Changes
Expand Down
42 changes: 26 additions & 16 deletions R/print.equivalence_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 798f2e7

Please sign in to comment.