@@ -163,7 +163,7 @@ check_mode_val <- function(mode) {
163163}
164164
165165
166- stop_incompatible_mode <- function (spec_modes , eng = NULL , cls = NULL ) {
166+ stop_incompatible_mode <- function (spec_modes , eng = NULL , cls = NULL , call ) {
167167 if (is.null(eng ) & is.null(cls )) {
168168 msg <- " Available modes are: "
169169 }
@@ -181,18 +181,18 @@ stop_incompatible_mode <- function(spec_modes, eng = NULL, cls = NULL) {
181181 msg ,
182182 glue :: glue_collapse(glue :: glue(" '{spec_modes}'" ), sep = " , " )
183183 )
184- rlang :: abort(msg )
184+ rlang :: abort(msg , call = call )
185185}
186186
187- stop_incompatible_engine <- function (spec_engs , mode ) {
187+ stop_incompatible_engine <- function (spec_engs , mode , call ) {
188188 msg <- glue :: glue(
189189 " Available engines for mode {mode} are: " ,
190190 glue :: glue_collapse(glue :: glue(" '{spec_engs}'" ), sep = " , " )
191191 )
192- rlang :: abort(msg )
192+ rlang :: abort(msg , call = call )
193193}
194194
195- stop_missing_engine <- function (cls ) {
195+ stop_missing_engine <- function (cls , call ) {
196196 info <-
197197 get_from_env(cls ) %> %
198198 dplyr :: group_by(mode ) %> %
@@ -201,11 +201,11 @@ stop_missing_engine <- function(cls) {
201201 " }" ),
202202 .groups = " drop" )
203203 if (nrow(info ) == 0 ) {
204- rlang :: abort(paste0(" No known engines for `" , cls , " ()`." ))
204+ rlang :: abort(paste0(" No known engines for `" , cls , " ()`." ), call = call )
205205 }
206206 msg <- paste0(info $ msg , collapse = " , " )
207207 msg <- paste(" Missing engine. Possible mode/engine combinations are:" , msg )
208- rlang :: abort(msg )
208+ rlang :: abort(msg , call = call )
209209}
210210
211211check_mode_for_new_engine <- function (cls , eng , mode ) {
@@ -218,11 +218,12 @@ check_mode_for_new_engine <- function(cls, eng, mode) {
218218
219219
220220# 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() ) {
222222
223223 all_modes <- get_from_env(paste0(cls , " _modes" ))
224224 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 )
226227 }
227228
228229 model_info <- rlang :: env_get(get_model_env(), cls )
@@ -237,7 +238,7 @@ check_spec_mode_engine_val <- function(cls, eng, mode) {
237238 )
238239
239240 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 )
241242 return (invisible (NULL ))
242243 }
243244
@@ -251,7 +252,8 @@ check_spec_mode_engine_val <- function(cls, eng, mode) {
251252 paste0(
252253 " Engine '" , eng , " ' is not supported for `" , cls , " ()`. See " ,
253254 " `show_engines('" , cls , " ')`."
254- )
255+ ),
256+ call = call
255257 )
256258 }
257259
@@ -265,9 +267,9 @@ check_spec_mode_engine_val <- function(cls, eng, mode) {
265267 spec_modes <- unique(c(" unknown" , spec_modes ))
266268
267269 if (is.null(mode ) || length(mode ) > 1 ) {
268- stop_incompatible_mode(spec_modes , eng )
270+ stop_incompatible_mode(spec_modes , eng , call = call )
269271 } else if (! (mode %in% spec_modes )) {
270- stop_incompatible_mode(spec_modes , eng )
272+ stop_incompatible_mode(spec_modes , eng , call = call )
271273 }
272274
273275 # ----------------------------------------------------------------------------
@@ -279,16 +281,16 @@ check_spec_mode_engine_val <- function(cls, eng, mode) {
279281 }
280282 spec_engs <- unique(spec_engs )
281283 if (! is.null(eng ) && ! (eng %in% spec_engs )) {
282- stop_incompatible_engine(spec_engs , mode )
284+ stop_incompatible_engine(spec_engs , mode , call = call )
283285 }
284286
285287 invisible (NULL )
286288}
287289
288- check_mode_with_no_engine <- function (cls , mode ) {
290+ check_mode_with_no_engine <- function (cls , mode , call ) {
289291 spec_modes <- get_from_env(paste0(cls , " _modes" ))
290292 if (! (mode %in% spec_modes )) {
291- stop_incompatible_mode(spec_modes , cls = cls )
293+ stop_incompatible_mode(spec_modes , cls = cls , call = call )
292294 }
293295}
294296
0 commit comments