@@ -111,7 +111,7 @@ StatSmooth <- ggproto("StatSmooth", Stat,
111
111
}
112
112
113
113
if (is.null(params $ formula )) {
114
- if (identical(method , " gam" )) {
114
+ if (identical(method , " gam" ) && is_installed( " mgcv " ) ) {
115
115
params $ formula <- y ~ s(x , bs = " cs" )
116
116
} else {
117
117
params $ formula <- y ~ x
@@ -133,7 +133,15 @@ StatSmooth <- ggproto("StatSmooth", Stat,
133
133
}
134
134
# If gam and gam's method is not specified by the user then use REML
135
135
if (identical(method , gam_method())) {
136
- params $ method.args $ method <- params $ method.args $ method %|| % " REML"
136
+ if (identical(method , stats :: lm )) {
137
+ cli :: cli_warn(c(
138
+ " The {.pkg mgcv} package must be installed to use \\
139
+ {.code method = \" gam\" }." ,
140
+ " Falling back to {.code method = \" lm\" }."
141
+ ))
142
+ } else {
143
+ params $ method.args $ method <- params $ method.args $ method %|| % " REML"
144
+ }
137
145
}
138
146
139
147
if (length(msg ) > 0 ) {
@@ -204,4 +212,10 @@ StatSmooth <- ggproto("StatSmooth", Stat,
204
212
)
205
213
206
214
# This function exists to silence an undeclared import warning
207
- gam_method <- function () mgcv :: gam
215
+ gam_method <- function () {
216
+ if (is_installed(" mgcv" )) {
217
+ mgcv :: gam
218
+ } else {
219
+ stats :: lm
220
+ }
221
+ }
0 commit comments