diff --git a/R/simple_slopes.R b/R/simple_slopes.R index 76f9ee5..aad76e7 100644 --- a/R/simple_slopes.R +++ b/R/simple_slopes.R @@ -337,9 +337,7 @@ sim_slopes <- function(model, pred, modx, mod2 = NULL, modx.values = NULL, # Since output columns are conditional, I call summ here to see what they will # be. I set vifs = FALSE to make sure it isn't fit due to user options. # Need proper name for test statistic\ - has_summ <- any(sapply(class(model), function(x) { - !is.null(getS3method("summ", x, optional = TRUE)) - })) + has_summ <- check_method(summ, model) tcol <- try(colnames(summary(model)$coefficients)[3], silent = TRUE) if (!is.null(tcol) & class(tcol) != "try-error") { tcol <- gsub("value", "val.", tcol) diff --git a/R/utils.R b/R/utils.R index bf6c863..ed380af 100644 --- a/R/utils.R +++ b/R/utils.R @@ -284,3 +284,19 @@ j_update <- function(mod, formula = NULL, data = NULL, offset = NULL, eval(call, env, call.env) } + +# adapted from https://stackoverflow.com/a/42742370 +# Looking for whether a method is defined for a given object (...) +# getS3method() doesn't work for something like merMod because the string +# "merMod" is not in the vector returned by class() +check_method <- function(generic, ...) { + ch <- deparse(substitute(generic)) + f <- X <- function(x, ...) UseMethod("X") + for(m in methods(ch)) assign(sub(ch, "X", m, fixed = TRUE), "body<-"(f, value = m)) + tryCatch({ + X(...) + TRUE + }, error = function(e) { + FALSE + }) +}