Skip to content

Commit

Permalink
Merge pull request #858 from jvparidon/jvp/refactor_glmmTMB_dependency
Browse files Browse the repository at this point in the history
Moved glmmTMB require statement in plot_type_ranef to come after the model class check
  • Loading branch information
strengejacke authored Oct 25, 2023
2 parents c52c7c4 + a22d489 commit 9e8b4de
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions R/plot_type_ranef.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,23 @@ plot_type_ranef <- function(model,
if (!requireNamespace("lme4", quietly = TRUE)) {
stop("Package 'lme4' required for this function to work, please install it.")
}
if (!requireNamespace("glmmTMB", quietly = TRUE)) {
stop("Package 'glmmTMB' required for this function to work, please install it.")
}

# get tidy output of summary ----

if (inherits(model, "glmmTMB"))
if (inherits(model, "glmmTMB")) {
if (!requireNamespace("glmmTMB", quietly = TRUE)) {
stop("Package 'glmmTMB' required for this function to work, please install it.")
}
rand.ef <- glmmTMB::ranef(model)[[1]]
else if (inherits(model, "MixMod")) {
} else {
rand.ef <- lme4::ranef(model)
if (!is.list(rand.ef)) {
rand.ef <- list(rand.ef)
names(rand.ef) <- insight::find_random(model, flatten = TRUE)
if (inherits(model, "MixMod")) {
if (!is.list(rand.ef)) {
rand.ef <- list(rand.ef)
names(rand.ef) <- insight::find_random(model, flatten = TRUE)
}
}
} else
rand.ef <- lme4::ranef(model)
}


if (inherits(model, "clmm"))
Expand Down

0 comments on commit 9e8b4de

Please sign in to comment.