Skip to content

Commit afa61f7

Browse files
committed
change fallback
1 parent f0c5590 commit afa61f7

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

R/stat-smooth.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ StatSmooth <- ggproto("StatSmooth", Stat,
110110
msg <- c(msg, paste0("method = '", method, "'"))
111111
}
112112

113+
if (identical(method, "gam") &&
114+
!prompt_install("mgcv", "for using {.code method = \"gam\"}")) {
115+
cli::cli_inform(c(
116+
"The {.arg method} was set to {.val gam}, but {.pkg mgcv} is not installed.",
117+
"!" = "Falling back to {.code method = \"lm\"}.",
118+
i = "Change the {.arg method} argument to silence this message."
119+
))
120+
method <- "lm"
121+
}
122+
113123
if (is.null(params$formula)) {
114124
if (identical(method, "gam")) {
115125
params$formula <- y ~ s(x, bs = "cs")

tests/testthat/test-geom-smooth.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ test_that("geom_smooth() works when one group fails", {
9898
expect_gte(nrow(ld), 2)
9999
})
100100

101-
test_that("a warning is thrown when `method = 'gam'` and {mgcv} is absent", {
101+
test_that("a fallback message is thrown when `method = 'gam'` and {mgcv} is absent", {
102102
p <- ggplot(mpg, aes(displ, hwy)) +
103103
geom_smooth(method = "gam", formula = y ~ x)
104104

105105
with_mocked_bindings(
106-
expect_warning(
107-
ggplot_build(p), regexp = "package must be installed"
106+
expect_message(
107+
ggplot_build(p), regexp = "Falling back to `method = \"lm\"`"
108108
),
109109
is_installed = function(...) FALSE
110110
)

0 commit comments

Comments
 (0)