Skip to content

Commit

Permalink
apply more involved suggestions and update snaps
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Aug 28, 2024
1 parent cc98613 commit 2134129
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
7 changes: 6 additions & 1 deletion R/augment.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ augment.model_fit <- function(x, new_data, eval_time = NULL, ...) {
"regression" = augment_regression(x, new_data),
"classification" = augment_classification(x, new_data),
"censored regression" = augment_censored(x, new_data, eval_time = eval_time),
cli::cli_abort("Unknown mode: {x$spec$mode}.")
cli::cli_abort(
c(
"Unknown mode {.val {x$spec$mode}}.",
"i" = "Model mode should be one of {.or {.val {all_modes}}}."
)
)
)
tibble::new_tibble(res)
}
Expand Down
5 changes: 4 additions & 1 deletion R/convert_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ check_dup_names <- function(x, y, call = rlang::caller_env()) {
common_names <- intersect(colnames(x), colnames(y))
if (length(common_names) > 0) {
cli::cli_abort(
"{.arg x} and {.arg y} have the name{?s} {.val {common_names}} in common.",
c(
"{.arg x} and {.arg y} have the name{?s} {.val {common_names}} in common.",
"i" = "Please ensure that {.arg x} and {.arg y} don't share any column names."
),
call = call
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ check_pred_type <- function(object, type, ..., call = rlang::caller_env()) {
}
if (!(type %in% pred_types))
cli::cli_abort(
"{.arg type} should be one of:{.arg {pred_types}}",
"{.arg type} should be one of {.or {.arg {pred_types}}}.",
call = call
)

Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/augment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# regression models

Code
augment(reg_form, head(mtcars[, -1]))
Condition
Error in `augment()`:
! Unknown mode "depeche".
i Model mode should be one of "classification", "regression", or "censored regression".

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/rand_forest_ranger.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Condition
Warning:
! 1000 columns were requested but there were 6 predictors in the data.
i 6 will be used.
i 6 predictors will be used.
Warning:
! 1000 samples were requested but there were 333 rows in the data.
i 333 will be used.
Expand All @@ -39,7 +39,7 @@
Condition
Warning:
! 1000 columns were requested but there were 6 predictors in the data.
i 6 will be used.
i 6 predictors will be used.
Warning:
! 1000 samples were requested but there were 333 rows in the data.
i 333 will be used.
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-augment.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ test_that('regression models', {

reg_form$spec$mode <- "depeche"

expect_error(augment(reg_form, head(mtcars[, -1])), "Unknown mode: depeche")
expect_snapshot(
error = TRUE,
augment(reg_form, head(mtcars[, -1]))
)

})

Expand Down

0 comments on commit 2134129

Please sign in to comment.