-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Summary
check_metrics() is exported and documented (via @rdname empty_ellipses) but is only called from tests. It has been replaced by check_metrics_arg() in the production code paths.
Location
Lines 384 to 456 in 3544816
| #' @export | |
| #' @keywords internal | |
| #' @rdname empty_ellipses | |
| #' @param object A `workflow` object. | |
| check_metrics <- function(x, object) { | |
| mode <- extract_spec_parsnip(object)$mode | |
| if (is.null(x)) { | |
| switch( | |
| mode, | |
| regression = { | |
| x <- yardstick::metric_set(rmse, rsq) | |
| }, | |
| classification = { | |
| x <- yardstick::metric_set(roc_auc, accuracy, brier_class) | |
| }, | |
| 'censored regression' = { | |
| x <- yardstick::metric_set(brier_survival) | |
| }, | |
| 'quantile regression' = { | |
| x <- yardstick::metric_set(weighted_interval_score) | |
| }, | |
| unknown = { | |
| cli::cli_abort( | |
| "Internal error: {.fn check_installs} should have | |
| caught an {.val unknown} mode." | |
| ) | |
| }, | |
| cli::cli_abort("Unknown {.val mode} for parsnip model.") | |
| ) | |
| return(x) | |
| } | |
| is_numeric_metric_set <- inherits(x, "numeric_metric_set") | |
| is_class_prob_metric_set <- inherits(x, "class_prob_metric_set") | |
| is_surv_metric_set <- inherits(x, c("survival_metric_set")) | |
| if ( | |
| !is_numeric_metric_set && !is_class_prob_metric_set && !is_surv_metric_set | |
| ) { | |
| cli::cli_abort( | |
| "The {.arg metrics} argument should be the results of | |
| {.fn yardstick::metric_set}." | |
| ) | |
| } | |
| if (mode == "regression" && !is_numeric_metric_set) { | |
| cli::cli_abort( | |
| c( | |
| "The parsnip model has {.code mode = 'regression'}, but {.arg metrics} | |
| is a metric set for a different model mode." | |
| ) | |
| ) | |
| } | |
| if (mode == "classification" && !is_class_prob_metric_set) { | |
| cli::cli_abort( | |
| c( | |
| "The parsnip model has {.code mode = 'classification'}, but {.arg metrics} | |
| is a metric set for a different model mode." | |
| ) | |
| ) | |
| } | |
| if (mode == "censored regression" && !is_surv_metric_set) { | |
| cli::cli_abort(c( | |
| "The parsnip model has {.code mode = 'censored regression'}, | |
| but {.arg metrics} is a metric set for a different model mode." | |
| )) | |
| } | |
| x | |
| } |
What it does
check_metrics() provides default metric sets based on model mode (regression, classification, censored regression, quantile regression) and validates that user-supplied metrics match the model mode.
Why it's superseded
The current code uses check_metrics_arg() instead. check_metrics() has no callers in R/ or inst/ -- it is only exercised by tests that were written against it directly.
Suggested fix
Since it is exported and documented, check whether any downstream packages (e.g., finetune, workflowsets) call it. Set the deprecation process for check_metrics() accordingly.