Skip to content

Commit 87314bc

Browse files
Merge pull request #517 from tidymodels/type-checkers
add rlang type checkers
2 parents be744a3 + e421511 commit 87314bc

26 files changed

+195
-112
lines changed

DESCRIPTION

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Authors@R: c(
77
person("Davis", "Vaughan", , "davis@posit.co", role = "aut"),
88
person("Emil", "Hvitfeldt", , "emil.hvitfeldt@posit.co", role = c("aut", "cre"),
99
comment = c(ORCID = "0000-0002-0679-1945")),
10-
person(given = "Posit Software, PBC", role = c("cph", "fnd"))
10+
person("Posit Software, PBC", role = c("cph", "fnd"))
1111
)
1212
Description: Tidy tools for quantifying how well model fits to a data set
1313
such as confusion matrices, class probability curve summaries, and
@@ -24,7 +24,7 @@ Imports:
2424
generics (>= 0.1.2),
2525
hardhat (>= 1.3.0),
2626
lifecycle (>= 1.0.3),
27-
rlang (>= 1.1.0),
27+
rlang (>= 1.1.4),
2828
tibble,
2929
tidyselect (>= 1.2.0),
3030
utils,
@@ -42,10 +42,84 @@ Suggests:
4242
tidyr
4343
VignetteBuilder:
4444
knitr
45-
Config/Needs/website:
46-
tidyverse/tidytemplate
45+
Config/Needs/website: tidyverse/tidytemplate
4746
Config/testthat/edition: 3
47+
Config/usethis/last-upkeep: 2024-10-24
4848
Encoding: UTF-8
4949
LazyData: true
5050
Roxygen: list(markdown = TRUE)
51-
RoxygenNote: 7.3.0
51+
RoxygenNote: 7.3.2
52+
Collate:
53+
'aaa-metrics.R'
54+
'import-standalone-types-check.R'
55+
'aaa-new.R'
56+
'aaa.R'
57+
'check-metric.R'
58+
'class-accuracy.R'
59+
'class-bal_accuracy.R'
60+
'class-detection_prevalence.R'
61+
'class-f_meas.R'
62+
'class-j_index.R'
63+
'class-kap.R'
64+
'class-mcc.R'
65+
'class-npv.R'
66+
'class-ppv.R'
67+
'class-precision.R'
68+
'class-recall.R'
69+
'class-sens.R'
70+
'class-spec.R'
71+
'conf_mat.R'
72+
'data.R'
73+
'deprecated-prob_helpers.R'
74+
'deprecated-template.R'
75+
'estimator-helpers.R'
76+
'event-level.R'
77+
'fair-aaa.R'
78+
'fair-demographic_parity.R'
79+
'fair-equal_opportunity.R'
80+
'fair-equalized_odds.R'
81+
'import-standalone-obj-type.R'
82+
'import-standalone-survival.R'
83+
'metric-tweak.R'
84+
'misc.R'
85+
'missings.R'
86+
'num-ccc.R'
87+
'num-huber_loss.R'
88+
'num-iic.R'
89+
'num-mae.R'
90+
'num-mape.R'
91+
'num-mase.R'
92+
'num-mpe.R'
93+
'num-msd.R'
94+
'num-poisson_log_loss.R'
95+
'num-pseudo_huber_loss.R'
96+
'num-rmse.R'
97+
'num-rpd.R'
98+
'num-rpiq.R'
99+
'num-rsq.R'
100+
'num-rsq_trad.R'
101+
'num-smape.R'
102+
'prob-average_precision.R'
103+
'prob-binary-thresholds.R'
104+
'prob-brier_class.R'
105+
'prob-classification_cost.R'
106+
'prob-gain_capture.R'
107+
'prob-gain_curve.R'
108+
'prob-helpers.R'
109+
'prob-lift_curve.R'
110+
'prob-mn_log_loss.R'
111+
'prob-pr_auc.R'
112+
'prob-pr_curve.R'
113+
'prob-roc_auc.R'
114+
'prob-roc_aunp.R'
115+
'prob-roc_aunu.R'
116+
'prob-roc_curve.R'
117+
'reexports.R'
118+
'surv-brier_survival.R'
119+
'surv-brier_survival_integrated.R'
120+
'surv-concordance_survival.R'
121+
'surv-roc_auc_survival.R'
122+
'surv-roc_curve_survival.R'
123+
'template.R'
124+
'validation.R'
125+
'yardstick-package.R'

R/aaa-metrics.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' General Function to Estimate Performance
22
#'
3-
#' This function estimates one or more common performance estimates depending
4-
#' on the class of `truth` (see **Value** below) and returns them in a three
3+
#' This function estimates one or more common performance estimates depending
4+
#' on the class of `truth` (see **Value** below) and returns them in a three
55
#' column tibble. If you wish to modify the metrics used or how they are used
66
#' see [metric_set()].
77
#'
@@ -305,8 +305,8 @@ format.metric_set <- function(x, ...) {
305305

306306
for (i in seq_along(metrics)) {
307307
cli::cli_text(
308-
"- {.fun {metric_names[i]}}, \\
309-
{tolower(metric_types[i])}{metric_desc_paddings[i]} | \\
308+
"- {.fun {metric_names[i]}},
309+
{tolower(metric_types[i])}{metric_desc_paddings[i]} |
310310
{metric_descs[i]}"
311311
)
312312
}
@@ -585,7 +585,7 @@ validate_inputs_are_functions <- function(fns, call = caller_env()) {
585585
if (!all_fns) {
586586
not_fn <- which(!is_fun_vec)
587587
cli::cli_abort(
588-
"All inputs to {.fn metric_set} must be functions. \\
588+
"All inputs to {.fn metric_set} must be functions.
589589
These inputs are not: {not_fn}.",
590590
call = call
591591
)
@@ -660,8 +660,8 @@ validate_function_class <- function(fns) {
660660
if ("metric_factory" %in% fn_cls) {
661661
factories <- fn_cls[fn_cls == "metric_factory"]
662662
cli::cli_abort(
663-
c("{cli::qty(factories)}The input{?s} {.arg {names(factories)}} \\
664-
{?is a/are} {.help [groupwise metric](yardstick::new_groupwise_metric)} \\
663+
c("{cli::qty(factories)}The input{?s} {.arg {names(factories)}}
664+
{?is a/are} {.help [groupwise metric](yardstick::new_groupwise_metric)}
665665
{?factory/factories} and must be passed a data-column before
666666
addition to a metric set.",
667667
"i" = "Did you mean to type e.g. `{names(factories)[1]}(col_name)`?"),

R/aaa-new.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ new_static_survival_metric <- function(fn, direction) {
6464
new_metric(fn, direction, class = "static_survival_metric")
6565
}
6666

67+
#' @include import-standalone-types-check.R
6768
new_metric <- function(fn, direction, class = NULL) {
68-
if (!is.function(fn)) {
69-
cli::cli_abort("{.arg fn} must be a function.")
70-
}
69+
check_function(fn)
7170

7271
direction <- arg_match(
7372
direction,

R/class-kap.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,16 @@ make_weighting_matrix <- function(weighting, n_levels, call = caller_env()) {
177177

178178

179179
validate_weighting <- function(x, call = caller_env()) {
180-
if (!is_string(x)) {
181-
cli::cli_abort("{.arg weighting} must be a string.", call = call)
182-
}
180+
check_string(x, arg = "weighting", call = call)
183181

184182
ok <- is_no_weighting(x) ||
185183
is_linear_weighting(x) ||
186184
is_quadratic_weighting(x)
187185

188186
if (!ok) {
189187
cli::cli_abort(
190-
"{.arg weighting} must be {.val none}, {.val linear}, or \\
191-
{.val quadratic}, not {.val {x}}.",
188+
"{.arg weighting} must be {.val none}, {.val linear}, or
189+
{.val quadratic}, not {.val {x}}.",
192190
call = call
193191
)
194192
}

R/class-precision.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ precision_multiclass <- function(data, estimator) {
179179

180180
warn_precision_undefined_binary <- function(event, count) {
181181
message <- c(
182-
"While computing binary {.fn precision}, no predicted events were \\
182+
"While computing binary {.fn precision}, no predicted events were
183183
detected (i.e. `true_positive + false_positive = 0`).",
184184
"Precision is undefined in this case, and `NA` will be returned."
185185
)
@@ -204,11 +204,11 @@ warn_precision_undefined_binary <- function(event, count) {
204204

205205
warn_precision_undefined_multiclass <- function(events, counts) {
206206
message <- c(
207-
"While computing multiclass {.fn precision}, some levels had no predicted \\
207+
"While computing multiclass {.fn precision}, some levels had no predicted
208208
events (i.e. `true_positive + false_positive = 0`).",
209-
"Precision is undefined in this case, and those levels will be removed \\
209+
"Precision is undefined in this case, and those levels will be removed
210210
from the averaged result.",
211-
"Note that the following number of true events actually occurred for each \\
211+
"Note that the following number of true events actually occurred for each
212212
problematic event level:",
213213
paste0("'", events, "': ", counts, collapse = ", ")
214214
)

R/class-recall.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ recall_multiclass <- function(data, estimator) {
180180

181181
warn_recall_undefined_binary <- function(event, count) {
182182
message <- c(
183-
"While computing binary {.fn recall}, no true events were detected \\
183+
"While computing binary {.fn recall}, no true events were detected
184184
(i.e. `true_positive + false_negative = 0`).",
185185
"Recall is undefined in this case, and `NA` will be returned."
186186
)
@@ -205,11 +205,11 @@ warn_recall_undefined_binary <- function(event, count) {
205205

206206
warn_recall_undefined_multiclass <- function(events, counts) {
207207
message <- c(
208-
"While computing multiclass {.fn recall}, some levels had no true events \\
208+
"While computing multiclass {.fn recall}, some levels had no true events
209209
(i.e. `true_positive + false_negative = 0`).",
210-
"Recall is undefined in this case, and those levels will be removed from \\
210+
"Recall is undefined in this case, and those levels will be removed from
211211
the averaged result.",
212-
"Note that the following number of predicted events actually occurred for \\
212+
"Note that the following number of predicted events actually occurred for
213213
each problematic event level:",
214214
paste0("'", events, "': ", counts, collapse = ", ")
215215
)

R/class-sens.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#'
5050
#' @param case_weights The optional column identifier for case weights.
5151
#' This should be an unquoted column name that evaluates to a numeric column
52-
#' in `data`. For `_vec()` functions, a numeric vector,
52+
#' in `data`. For `_vec()` functions, a numeric vector,
5353
#' [hardhat::importance_weights()], or [hardhat::frequency_weights()].
5454
#'
5555
#' @param event_level A single string. Either `"first"` or `"second"` to specify
@@ -277,7 +277,7 @@ sens_multiclass <- function(data, estimator) {
277277

278278
warn_sens_undefined_binary <- function(event, count) {
279279
message <- c(
280-
"While computing binary {.fn sens}, no true events were detected \\
280+
"While computing binary {.fn sens}, no true events were detected
281281
(i.e. `true_positive + false_negative = 0`).",
282282
"Sensitivity is undefined in this case, and `NA` will be returned."
283283
)
@@ -302,11 +302,11 @@ warn_sens_undefined_binary <- function(event, count) {
302302

303303
warn_sens_undefined_multiclass <- function(events, counts) {
304304
message <- c(
305-
"While computing multiclass {.fn sens}, some levels had no true events \\
305+
"While computing multiclass {.fn sens}, some levels had no true events
306306
(i.e. `true_positive + false_negative = 0`).",
307-
"Sensitivity is undefined in this case, and those levels will be removed \\
307+
"Sensitivity is undefined in this case, and those levels will be removed
308308
from the averaged result.",
309-
"Note that the following number of predicted events actually occurred for \\
309+
"Note that the following number of predicted events actually occurred for
310310
each problematic event level:",
311311
paste0("'", events, "': ", counts, collapse = ", ")
312312
)

R/class-spec.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ spec_multiclass <- function(data, estimator) {
248248

249249
warn_spec_undefined_binary <- function(event, count) {
250250
message <- c(
251-
"While computing binary {.fn spec}, no true negatives were detected \\
251+
"While computing binary {.fn spec}, no true negatives were detected
252252
(i.e. `true_negative + false_positive = 0`).",
253253
"Specificity is undefined in this case, and `NA` will be returned."
254254
)
@@ -273,11 +273,11 @@ warn_spec_undefined_binary <- function(event, count) {
273273

274274
warn_spec_undefined_multiclass <- function(events, counts) {
275275
message <- c(
276-
"While computing multiclass {.fn spec}, some levels had no true negatives \\
276+
"While computing multiclass {.fn spec}, some levels had no true negatives
277277
(i.e. `true_negative + false_positive = 0`).",
278-
"Specificity is undefined in this case, and those levels will be removed \\
278+
"Specificity is undefined in this case, and those levels will be removed
279279
from the averaged result.",
280-
"Note that the following number of predicted negatives actually occurred \\
280+
"Note that the following number of predicted negatives actually occurred
281281
for each problematic event level:",
282282
paste0("'", events, "': ", counts, collapse = ", ")
283283
)

R/conf_mat.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ flatten <- function(xtab, call = caller_env()) {
297297
n_row <- nrow(xtab)
298298
if (n_row != n_col) {
299299
cli::cli_abort(
300-
"{.arg x} must have equal dimensions. \\
300+
"{.arg x} must have equal dimensions.
301301
{.arg x} has {n_col} columns and {n_row} rows.",
302302
call = call
303303
)

R/fair-aaa.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ new_groupwise_metric <- function(fn, name, aggregate, direction = "minimize") {
143143

144144
if (by_str %in% gp_vars) {
145145
cli::cli_abort(
146-
"Metric is internally grouped by {.field {by_str}}; grouping \\
146+
"Metric is internally grouped by {.field {by_str}}; grouping
147147
{.arg data} by {.field {by_str}} is not well-defined."
148148
)
149149
}

0 commit comments

Comments
 (0)