diff --git a/NEWS.md b/NEWS.md index c996cceb2..275f91589 100644 --- a/NEWS.md +++ b/NEWS.md @@ -29,6 +29,7 @@ New: * `rvar` column from `get_draws()` is now printed by default. * Matrix columns with 1 column are supported. Fixes errors when a variable was transformed by `scale()`, for example. Thanks to @barryrowlingson for the report. * Much faster inference with `inferences(method="boot")`. Thanks to @nremenyi for issue #1352. +* `hypothesis=~pairwise` only errors when there are more than 300 comparisons. `options(marginaleffects_safe=FALSE)` to disable this check. Bugs: diff --git a/R/hypothesis_formula.R b/R/hypothesis_formula.R index 29bed01f3..2b6d5fcf0 100644 --- a/R/hypothesis_formula.R +++ b/R/hypothesis_formula.R @@ -22,16 +22,16 @@ hypothesis_formula_list <- list( pairwise = list( ratio = list( comparison = function(x) { + safe_mode <- getOption("marginaleffects_safe", default = TRUE) + if (length(x) > 25 && isTRUE(safe_mode)) { + msg <- "This command will generate many estimates. Set `options(marginaleffects_safe=FALSE)` to circumvent this guardrail." + stop(msg, call. = FALSE) + } out <- outer(x, x, "/") diag(out) <- NA out[upper.tri(out)] <- NA # Set lower triangle to NA out <- as.vector(out) out <- out[!is.na(out)] # Keep only non-NA values - safe_mode <- getOption("marginaleffects_safe", default = TRUE) - if (length(out) > 25 && isTRUE(safe_mode)) { - msg <- "This command will generate many estimates. Set `options(marginaleffects_safe=FALSE)` to circumvent this guardrail." - stop(msg, call. = FALSE) - } out }, label = function(x) { @@ -44,16 +44,16 @@ hypothesis_formula_list <- list( }), difference = list( comparison = function(x) { + safe_mode <- getOption("marginaleffects_safe", default = TRUE) + if (length(x) > 25 && isTRUE(safe_mode)) { + msg <- "This command will generate many estimates. Set `options(marginaleffects_safe=FALSE)` to circumvent this guardrail." + stop(msg, call. = FALSE) + } out <- outer(x, x, "-") diag(out) <- NA out[upper.tri(out)] <- NA # Set lower triangle to NA out <- as.vector(out) out <- out[!is.na(out)] # Keep only non-NA values - safe_mode <- getOption("marginaleffects_safe", default = TRUE) - if (length(out) > 25 && isTRUE(safe_mode)) { - msg <- "This command will generate many estimates. Set `options(marginaleffects_safe=FALSE)` to circumvent this guardrail." - stop(msg, call. = FALSE) - } out }, label = function(x) {