From 87dd2cc73d71ea5e6311d82bcca82234b9caedf0 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Mon, 11 Sep 2023 13:05:27 -0400 Subject: [PATCH] bugfix: invlink(link) --- R/marginal_means.R | 2 +- R/sanitize_type.R | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/R/marginal_means.R b/R/marginal_means.R index 75c043466..235bf3062 100644 --- a/R/marginal_means.R +++ b/R/marginal_means.R @@ -191,7 +191,7 @@ marginal_means <- function(model, } # if type is NULL, we backtransform if relevant - type_string <- sanitize_type(model = model, type = type, calling_function = "predictions") + type_string <- sanitize_type(model = model, type = type, calling_function = "marginal_means") if (type_string == "invlink(link)") { type_call <- "link" } else { diff --git a/R/sanitize_type.R b/R/sanitize_type.R index bb39bf745..6c1baa59c 100644 --- a/R/sanitize_type.R +++ b/R/sanitize_type.R @@ -3,14 +3,16 @@ #' @param model model object #' @param type character vector #' @noRd -sanitize_type <- function(model, type, calling_function = NULL) { +sanitize_type <- function(model, type, calling_function = "raw") { checkmate::assert_character(type, len = 1, null.ok = TRUE) cl <- class(model)[1] if (!cl %in% type_dictionary$class) { cl <- "other" } dict <- type_dictionary - if (calling_function %in% c("slopes", "comparisons")) { + # raw is often invoked by `get_predict()`, which is required for {clarify} and others. + # we only allow invlink(link) in predictions() and marginal_means(), which are handled by {marginaleffects} + if (!calling_function %in% c("predictions", "marginal_means")) { dict <- dict[dict$type != "invlink(link)", , drop = FALSE] }