Skip to content

Commit f799dba

Browse files
authored
Merge pull request #552 from tidymodels/make_strata-warnings
Switch to cli for `make_strata()`
2 parents 580a12f + 7592d3e commit f799dba

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

R/make_strata.R

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,18 @@ make_strata <- function(x, breaks = 4, nunique = 5, pool = .1, depth = 20) {
7777

7878
## This should really be based on some combo of rate and number.
7979
if (all(pcts < pool)) {
80-
rlang::warn(c(
80+
cli_warn(c(
8181
"Too little data to stratify.",
82-
"Resampling will be unstratified."
82+
"*" = "Resampling will be unstratified."
8383
))
8484
return(factor(rep("strata1", n)))
8585
}
8686

8787
if (pool < default_pool & any(pcts < default_pool)) {
88-
rlang::warn(c(
89-
paste0(
90-
"Stratifying groups that make up ",
91-
round(100 * pool), "% of the data may be ",
92-
"statistically risky."
93-
),
94-
"Consider increasing `pool` to at least 0.1"
88+
cli_warn(c(
89+
"Stratifying groups that make up {round(100 * pool)}% of the data may
90+
be statistically risky.",
91+
i = "Consider increasing {.arg pool} to at least 0.1."
9592
))
9693
}
9794

@@ -104,25 +101,23 @@ make_strata <- function(x, breaks = 4, nunique = 5, pool = .1, depth = 20) {
104101
out <- factor(as.character(x))
105102
} else {
106103
if (breaks < 2) {
107-
rlang::warn(c(
108-
"The bins specified by `breaks` must be >=2.",
109-
"Resampling will be unstratified."
104+
cli_warn(c(
105+
"The bins specified by {.arg breaks} must be >=2.",
106+
"*" = "Resampling will be unstratified."
110107
))
111108
return(factor(rep("strata1", n)))
112109
} else if (floor(n / breaks) < depth) {
113-
rlang::warn(c(
114-
paste0(
115-
"The number of observations in each quantile is ",
116-
"below the recommended threshold of ", depth, "."
117-
),
118-
paste0("Stratification will use ", floor(n / depth), " breaks instead.")
110+
cli_warn(c(
111+
"The number of observations in each quantile is below the recommended
112+
threshold of {depth}.",
113+
"*" = "Stratification will use {floor(n / depth)} breaks instead."
119114
))
120115
}
121116
breaks <- min(breaks, floor(n / depth))
122117
if (breaks < 2) {
123-
rlang::warn(c(
118+
cli_warn(c(
124119
"Too little data to stratify.",
125-
"Resampling will be unstratified."
120+
"*" = "Resampling will be unstratified."
126121
))
127122
return(factor(rep("strata1", n)))
128123
}

tests/testthat/_snaps/make_strata.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Condition
1515
Warning:
1616
Stratifying groups that make up 5% of the data may be statistically risky.
17-
* Consider increasing `pool` to at least 0.1
17+
i Consider increasing `pool` to at least 0.1.
1818

1919
---
2020

@@ -23,7 +23,7 @@
2323
Condition
2424
Warning:
2525
Stratifying groups that make up 5% of the data may be statistically risky.
26-
* Consider increasing `pool` to at least 0.1
26+
i Consider increasing `pool` to at least 0.1.
2727

2828
# bad data
2929

@@ -41,7 +41,7 @@
4141
Condition
4242
Warning:
4343
Stratifying groups that make up 6% of the data may be statistically risky.
44-
* Consider increasing `pool` to at least 0.1
44+
i Consider increasing `pool` to at least 0.1.
4545

4646
---
4747

tests/testthat/_snaps/vfold.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Condition
66
Warning:
77
Stratifying groups that make up 1% of the data may be statistically risky.
8-
* Consider increasing `pool` to at least 0.1
8+
i Consider increasing `pool` to at least 0.1.
99

1010
# strata arg is checked
1111

0 commit comments

Comments
 (0)