Skip to content

Commit 57825cf

Browse files
committed
check_outcome now indicates wrong input
1 parent 9c42ed4 commit 57825cf

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

R/misc.R

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,21 +336,33 @@ check_outcome <- function(y, spec) {
336336
if (spec$mode == "regression") {
337337
outcome_is_numeric <- if (is.atomic(y)) {is.numeric(y)} else {all(map_lgl(y, is.numeric))}
338338
if (!outcome_is_numeric) {
339-
rlang::abort("For a regression model, the outcome should be numeric.")
339+
cls <- class(y)[[1]]
340+
abort(paste0(
341+
"For a regression model, the outcome should be `numeric`, ",
342+
"not a `", cls, "`."
343+
))
340344
}
341345
}
342346

343347
if (spec$mode == "classification") {
344348
outcome_is_factor <- if (is.atomic(y)) {is.factor(y)} else {all(map_lgl(y, is.factor))}
345349
if (!outcome_is_factor) {
346-
rlang::abort("For a classification model, the outcome should be a factor.")
350+
cls <- class(y)[[1]]
351+
abort(paste0(
352+
"For a classification model, the outcome should be a `factor`, ",
353+
"not a `", cls, "`."
354+
))
347355
}
348356
}
349357

350358
if (spec$mode == "censored regression") {
351359
outcome_is_surv <- inherits(y, "Surv")
352360
if (!outcome_is_surv) {
353-
rlang::abort("For a censored regression model, the outcome should be a `Surv` object.")
361+
cls <- class(y)[[1]]
362+
abort(paste0(
363+
"For a censored regression model, the outcome should be a `Surv` object, ",
364+
"not a `", cls, "`."
365+
))
354366
}
355367
}
356368

0 commit comments

Comments
 (0)