From 7592d3e1a354c4b6e974e3777ad52ad9ab8aa675 Mon Sep 17 00:00:00 2001 From: Hannah Frick Date: Fri, 27 Sep 2024 07:50:18 +0100 Subject: [PATCH] switch to cli --- R/make_strata.R | 35 ++++++++++++---------------- tests/testthat/_snaps/make_strata.md | 6 ++--- tests/testthat/_snaps/vfold.md | 2 +- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/R/make_strata.R b/R/make_strata.R index af23003e..11597669 100644 --- a/R/make_strata.R +++ b/R/make_strata.R @@ -77,21 +77,18 @@ make_strata <- function(x, breaks = 4, nunique = 5, pool = .1, depth = 20) { ## This should really be based on some combo of rate and number. if (all(pcts < pool)) { - rlang::warn(c( + cli_warn(c( "Too little data to stratify.", - "Resampling will be unstratified." + "*" = "Resampling will be unstratified." )) return(factor(rep("strata1", n))) } if (pool < default_pool & any(pcts < default_pool)) { - rlang::warn(c( - paste0( - "Stratifying groups that make up ", - round(100 * pool), "% of the data may be ", - "statistically risky." - ), - "Consider increasing `pool` to at least 0.1" + cli_warn(c( + "Stratifying groups that make up {round(100 * pool)}% of the data may + be statistically risky.", + i = "Consider increasing {.arg pool} to at least 0.1." )) } @@ -104,25 +101,23 @@ make_strata <- function(x, breaks = 4, nunique = 5, pool = .1, depth = 20) { out <- factor(as.character(x)) } else { if (breaks < 2) { - rlang::warn(c( - "The bins specified by `breaks` must be >=2.", - "Resampling will be unstratified." + cli_warn(c( + "The bins specified by {.arg breaks} must be >=2.", + "*" = "Resampling will be unstratified." )) return(factor(rep("strata1", n))) } else if (floor(n / breaks) < depth) { - rlang::warn(c( - paste0( - "The number of observations in each quantile is ", - "below the recommended threshold of ", depth, "." - ), - paste0("Stratification will use ", floor(n / depth), " breaks instead.") + cli_warn(c( + "The number of observations in each quantile is below the recommended + threshold of {depth}.", + "*" = "Stratification will use {floor(n / depth)} breaks instead." )) } breaks <- min(breaks, floor(n / depth)) if (breaks < 2) { - rlang::warn(c( + cli_warn(c( "Too little data to stratify.", - "Resampling will be unstratified." + "*" = "Resampling will be unstratified." )) return(factor(rep("strata1", n))) } diff --git a/tests/testthat/_snaps/make_strata.md b/tests/testthat/_snaps/make_strata.md index 2c5ff244..0242b422 100644 --- a/tests/testthat/_snaps/make_strata.md +++ b/tests/testthat/_snaps/make_strata.md @@ -14,7 +14,7 @@ Condition Warning: Stratifying groups that make up 5% of the data may be statistically risky. - * Consider increasing `pool` to at least 0.1 + i Consider increasing `pool` to at least 0.1. --- @@ -23,7 +23,7 @@ Condition Warning: Stratifying groups that make up 5% of the data may be statistically risky. - * Consider increasing `pool` to at least 0.1 + i Consider increasing `pool` to at least 0.1. # bad data @@ -41,7 +41,7 @@ Condition Warning: Stratifying groups that make up 6% of the data may be statistically risky. - * Consider increasing `pool` to at least 0.1 + i Consider increasing `pool` to at least 0.1. --- diff --git a/tests/testthat/_snaps/vfold.md b/tests/testthat/_snaps/vfold.md index 07bf38b2..f19b3fce 100644 --- a/tests/testthat/_snaps/vfold.md +++ b/tests/testthat/_snaps/vfold.md @@ -5,7 +5,7 @@ Condition Warning: Stratifying groups that make up 1% of the data may be statistically risky. - * Consider increasing `pool` to at least 0.1 + i Consider increasing `pool` to at least 0.1. # strata arg is checked