diff --git a/R/misc.R b/R/misc.R index 2c6eb264d..942285b26 100644 --- a/R/misc.R +++ b/R/misc.R @@ -617,17 +617,13 @@ check_nominal_type <- function(x, lvl) { was_factor <- fac_ref_cols[!(fac_ref_cols %in% fac_act_cols)] if (length(was_factor) > 0) { - rlang::warn( - paste0( - " There ", - ifelse(length(was_factor) > 1, "were ", "was "), - length(was_factor), - ifelse(length(was_factor) > 1, " columns ", " column "), - "that ", - ifelse(length(was_factor) > 1, "were factors ", "was a factor "), - "when the recipe was prepped:\n ", - paste0("'", was_factor, "'", collapse = ", "), - ".\n This may cause errors when processing new data." + cli::cli_warn( + c( + "!" = "There {?w/was/were} {length(was_factor)} column{?s} that \\ + {?was a factor/were factors} when the recipe was prepped: \\ + ", + "*" = "{.and {.var {was_factor}}}", + "i" = "This may cause errors when processing new data." ) ) } diff --git a/tests/testthat/_snaps/nomial_types.md b/tests/testthat/_snaps/nomial_types.md index 0451a5a18..3424d386c 100644 --- a/tests/testthat/_snaps/nomial_types.md +++ b/tests/testthat/_snaps/nomial_types.md @@ -4,9 +4,19 @@ check_nominal_type(te, rec$orig_lvls) Condition Warning: - There were 2 columns that were factors when the recipe was prepped: - 'city', 'zip'. - This may cause errors when processing new data. + ! There were 2 columns that were factors when the recipe was prepped: + * `city` and `zip` + i This may cause errors when processing new data. + +# missing single factor + + Code + check_nominal_type(te, rec$orig_lvls) + Condition + Warning: + ! There was 1 column that was a factor when the recipe was prepped: + * `city` + i This may cause errors when processing new data. # missing factors with skipping @@ -14,7 +24,7 @@ check_nominal_type(te, rec$orig_lvls) Condition Warning: - There were 2 columns that were factors when the recipe was prepped: - 'city', 'zip'. - This may cause errors when processing new data. + ! There were 2 columns that were factors when the recipe was prepped: + * `city` and `zip` + i This may cause errors when processing new data. diff --git a/tests/testthat/_snaps/stringsAsFactors.md b/tests/testthat/_snaps/stringsAsFactors.md index 77bc3fef9..b7bea98be 100644 --- a/tests/testthat/_snaps/stringsAsFactors.md +++ b/tests/testthat/_snaps/stringsAsFactors.md @@ -4,9 +4,9 @@ rec1_as_str <- bake(rec1, new_data = as_str) Condition Warning: - There were 2 columns that were factors when the recipe was prepped: - 'fact', 'ord'. - This may cause errors when processing new data. + ! There were 2 columns that were factors when the recipe was prepped: + * `fact` and `ord` + i This may cause errors when processing new data. # strings_as_factors = TRUE @@ -14,7 +14,7 @@ rec2_as_str <- bake(rec2, new_data = as_str) Condition Warning: - There were 2 columns that were factors when the recipe was prepped: - 'fact', 'ord'. - This may cause errors when processing new data. + ! There were 2 columns that were factors when the recipe was prepped: + * `fact` and `ord` + i This may cause errors when processing new data. diff --git a/tests/testthat/test-nomial_types.R b/tests/testthat/test-nomial_types.R index 43abf5c1b..70165bd50 100644 --- a/tests/testthat/test-nomial_types.R +++ b/tests/testthat/test-nomial_types.R @@ -140,6 +140,23 @@ test_that("missing factors", { expect_snapshot(check_nominal_type(te, rec$orig_lvls)) }) +test_that("missing single factor", { + tr <- + Sacramento_fac %>% + select(city) %>% + slice(1:500) + te <- + Sacramento_chr %>% + select(city) %>% + slice(501:932) + + rec <- + recipe( ~ ., data = tr) %>% + prep(training = tr) + + expect_snapshot(check_nominal_type(te, rec$orig_lvls)) +}) + test_that("missing factors with skipping", { tr <- Sacramento_fac %>%