@@ -163,7 +163,7 @@ check_mode_val <- function(mode) {
163
163
}
164
164
165
165
166
- stop_incompatible_mode <- function (spec_modes , eng = NULL , cls = NULL ) {
166
+ stop_incompatible_mode <- function (spec_modes , eng = NULL , cls = NULL , call ) {
167
167
if (is.null(eng ) & is.null(cls )) {
168
168
msg <- " Available modes are: "
169
169
}
@@ -181,18 +181,18 @@ stop_incompatible_mode <- function(spec_modes, eng = NULL, cls = NULL) {
181
181
msg ,
182
182
glue :: glue_collapse(glue :: glue(" '{spec_modes}'" ), sep = " , " )
183
183
)
184
- rlang :: abort(msg )
184
+ rlang :: abort(msg , call = call )
185
185
}
186
186
187
- stop_incompatible_engine <- function (spec_engs , mode ) {
187
+ stop_incompatible_engine <- function (spec_engs , mode , call ) {
188
188
msg <- glue :: glue(
189
189
" Available engines for mode {mode} are: " ,
190
190
glue :: glue_collapse(glue :: glue(" '{spec_engs}'" ), sep = " , " )
191
191
)
192
- rlang :: abort(msg )
192
+ rlang :: abort(msg , call = call )
193
193
}
194
194
195
- stop_missing_engine <- function (cls ) {
195
+ stop_missing_engine <- function (cls , call ) {
196
196
info <-
197
197
get_from_env(cls ) %> %
198
198
dplyr :: group_by(mode ) %> %
@@ -201,11 +201,11 @@ stop_missing_engine <- function(cls) {
201
201
" }" ),
202
202
.groups = " drop" )
203
203
if (nrow(info ) == 0 ) {
204
- rlang :: abort(paste0(" No known engines for `" , cls , " ()`." ))
204
+ rlang :: abort(paste0(" No known engines for `" , cls , " ()`." ), call = call )
205
205
}
206
206
msg <- paste0(info $ msg , collapse = " , " )
207
207
msg <- paste(" Missing engine. Possible mode/engine combinations are:" , msg )
208
- rlang :: abort(msg )
208
+ rlang :: abort(msg , call = call )
209
209
}
210
210
211
211
check_mode_for_new_engine <- function (cls , eng , mode ) {
@@ -218,11 +218,12 @@ check_mode_for_new_engine <- function(cls, eng, mode) {
218
218
219
219
220
220
# check if class and mode and engine are compatible
221
- check_spec_mode_engine_val <- function (cls , eng , mode ) {
221
+ check_spec_mode_engine_val <- function (cls , eng , mode , call = caller_env() ) {
222
222
223
223
all_modes <- get_from_env(paste0(cls , " _modes" ))
224
224
if (! (mode %in% all_modes )) {
225
- rlang :: abort(paste0(" '" , mode , " ' is not a known mode for model `" , cls , " ()`." ))
225
+ rlang :: abort(paste0(" '" , mode , " ' is not a known mode for model `" , cls , " ()`." ),
226
+ call = call )
226
227
}
227
228
228
229
model_info <- rlang :: env_get(get_model_env(), cls )
@@ -237,7 +238,7 @@ check_spec_mode_engine_val <- function(cls, eng, mode) {
237
238
)
238
239
239
240
if (nrow(model_info_parsnip_only ) == 0 ) {
240
- check_mode_with_no_engine(cls , mode )
241
+ check_mode_with_no_engine(cls , mode , call = call )
241
242
return (invisible (NULL ))
242
243
}
243
244
@@ -251,7 +252,8 @@ check_spec_mode_engine_val <- function(cls, eng, mode) {
251
252
paste0(
252
253
" Engine '" , eng , " ' is not supported for `" , cls , " ()`. See " ,
253
254
" `show_engines('" , cls , " ')`."
254
- )
255
+ ),
256
+ call = call
255
257
)
256
258
}
257
259
@@ -265,9 +267,9 @@ check_spec_mode_engine_val <- function(cls, eng, mode) {
265
267
spec_modes <- unique(c(" unknown" , spec_modes ))
266
268
267
269
if (is.null(mode ) || length(mode ) > 1 ) {
268
- stop_incompatible_mode(spec_modes , eng )
270
+ stop_incompatible_mode(spec_modes , eng , call = call )
269
271
} else if (! (mode %in% spec_modes )) {
270
- stop_incompatible_mode(spec_modes , eng )
272
+ stop_incompatible_mode(spec_modes , eng , call = call )
271
273
}
272
274
273
275
# ----------------------------------------------------------------------------
@@ -279,16 +281,16 @@ check_spec_mode_engine_val <- function(cls, eng, mode) {
279
281
}
280
282
spec_engs <- unique(spec_engs )
281
283
if (! is.null(eng ) && ! (eng %in% spec_engs )) {
282
- stop_incompatible_engine(spec_engs , mode )
284
+ stop_incompatible_engine(spec_engs , mode , call = call )
283
285
}
284
286
285
287
invisible (NULL )
286
288
}
287
289
288
- check_mode_with_no_engine <- function (cls , mode ) {
290
+ check_mode_with_no_engine <- function (cls , mode , call ) {
289
291
spec_modes <- get_from_env(paste0(cls , " _modes" ))
290
292
if (! (mode %in% spec_modes )) {
291
- stop_incompatible_mode(spec_modes , cls = cls )
293
+ stop_incompatible_mode(spec_modes , cls = cls , call = call )
292
294
}
293
295
}
294
296
0 commit comments