Skip to content

Commit 448a74d

Browse files
author
‘topepo’
committed
route some spec updating calls
1 parent d5166a7 commit 448a74d

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

R/mars.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,23 @@ multi_predict._earth <-
161161
object$fit$call[[i]] <- eval_tidy(object$fit$call[[i]])
162162
}
163163

164-
msg <-
165-
c("x" = "Please use {.code keepxy = TRUE} as an option to enable submodel
164+
msg <-
165+
c("x" = "Please use {.code keepxy = TRUE} as an option to enable submodel
166166
predictions with earth.")
167167
if (any(names(object$fit$call) == "keepxy")) {
168-
if (!isTRUE(object$fit$call$keepxy))
169-
cli::cli_abort(msg)
168+
if (!isTRUE(object$fit$call$keepxy)) {
169+
cli::cli_abort(msg)
170+
}
170171
} else {
171172
cli::cli_abort(msg)
172173
}
173174

174175
if (is.null(type)) {
175-
if (object$spec$mode == "classification")
176+
if (object$spec$mode == "classification") {
176177
type <- "class"
177-
else
178+
} else {
178179
type <- "numeric"
180+
}
179181
}
180182

181183
res <-

R/misc.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,21 +418,21 @@ check_outcome <- function(y, spec) {
418418
#' @export
419419
#' @keywords internal
420420
#' @rdname add_on_exports
421-
check_final_param <- function(x) {
421+
check_final_param <- function(x, call = rlang::caller_env()) {
422422
if (is.null(x)) {
423423
return(invisible(x))
424424
}
425425
if (!is.list(x) & !tibble::is_tibble(x)) {
426-
cli::cli_abort("The parameter object should be a list or tibble.")
426+
cli::cli_abort("The parameter object should be a list or tibble.", call = call)
427427
}
428428
if (tibble::is_tibble(x) && nrow(x) > 1) {
429-
cli::cli_abort("The parameter tibble should have a single row.")
429+
cli::cli_abort("The parameter tibble should have a single row.", call = call)
430430
}
431431
if (tibble::is_tibble(x)) {
432432
x <- as.list(x)
433433
}
434434
if (length(names) == 0 || any(names(x) == "")) {
435-
cli::cli_abort("All values in {.arg parameters} should have a name.")
435+
cli::cli_abort("All values in {.arg parameters} should have a name.", call = call)
436436
}
437437

438438
invisible(x)
@@ -441,7 +441,7 @@ check_final_param <- function(x) {
441441
#' @export
442442
#' @keywords internal
443443
#' @rdname add_on_exports
444-
update_main_parameters <- function(args, param) {
444+
update_main_parameters <- function(args, param, call = rlang::caller_env()) {
445445
if (length(param) == 0) {
446446
return(args)
447447
}
@@ -454,7 +454,8 @@ update_main_parameters <- function(args, param) {
454454
extra_args <- names(param)[has_extra_args]
455455
if (any(has_extra_args)) {
456456
cli::cli_abort(
457-
"Argument{?s} {.arg {extra_args}} {?is/are} not a main argument."
457+
"Argument{?s} {.arg {extra_args}} {?is/are} not a main argument.",
458+
call = call
458459
)
459460
}
460461
param <- param[!has_extra_args]

R/update.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ update_spec <- function(object, parameters, args_enquo_list, fresh, cls, ...,
6464
eng_args <- update_engine_parameters(object$eng_args, fresh, ...)
6565

6666
if (!is.null(parameters)) {
67-
parameters <- check_final_param(parameters)
67+
parameters <- check_final_param(parameters, call = call)
6868
}
6969

70-
args <- update_main_parameters(args_enquo_list, parameters)
70+
args <- update_main_parameters(args_enquo_list, parameters, call = call)
7171

7272
if (fresh) {
7373
object$args <- args

tests/testthat/_snaps/update.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,31 +196,31 @@
196196
Code
197197
expr1 %>% update(param_tibb)
198198
Condition
199-
Error in `update_main_parameters()`:
199+
Error in `update()`:
200200
! Argument `nlambda` is not a main argument.
201201

202202
---
203203

204204
Code
205205
expr1 %>% update(param_list)
206206
Condition
207-
Error in `update_main_parameters()`:
207+
Error in `update()`:
208208
! Argument `nlambda` is not a main argument.
209209

210210
---
211211

212212
Code
213213
expr1 %>% update(parameters = "wat")
214214
Condition
215-
Error in `check_final_param()`:
215+
Error in `update()`:
216216
! The parameter object should be a list or tibble.
217217

218218
---
219219

220220
Code
221221
expr1 %>% update(parameters = tibble::tibble(wat = "wat"))
222222
Condition
223-
Error in `update_main_parameters()`:
223+
Error in `update()`:
224224
! Argument `wat` is not a main argument.
225225

226226
---

0 commit comments

Comments
 (0)