Skip to content

check outcome class conditional on whether y is atomic #835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,13 @@ check_outcome <- function(y, spec) {
if (spec$mode == "unknown") {
return(invisible(NULL))
} else if (spec$mode == "regression") {
if (!all(map_lgl(y, is.numeric))) {
outcome_is_numeric <- if (is.atomic(y)) {is.numeric(y)} else {all(map_lgl(y, is.numeric))}
if (!outcome_is_numeric) {
rlang::abort("For a regression model, the outcome should be numeric.")
}
} else if (spec$mode == "classification") {
if (!all(map_lgl(y, is.factor))) {
outcome_is_factor <- if (is.atomic(y)) {is.factor(y)} else {all(map_lgl(y, is.factor))}
if (!outcome_is_factor) {
rlang::abort("For a classification model, the outcome should be a factor.")
}
} else if (spec$mode == "censored regression") {
Expand Down