From 3eac33a0efd3e2f01b62ec1960e5c5e71f2e41ce Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 24 May 2024 14:53:53 -0700 Subject: [PATCH] update tests to no use everything() --- tests/testthat/_snaps/class.md | 2 +- tests/testthat/_snaps/colcheck.md | 4 ++-- tests/testthat/_snaps/cut.md | 2 +- tests/testthat/_snaps/missing.md | 2 +- tests/testthat/_snaps/profile.md | 3 ++- tests/testthat/_snaps/shuffle.md | 6 +++--- tests/testthat/test-class.R | 10 +++++----- tests/testthat/test-colcheck.R | 16 ++++++++-------- tests/testthat/test-cut.R | 2 +- tests/testthat/test-indicate_na.R | 4 ++-- tests/testthat/test-missing.R | 4 ++-- tests/testthat/test-naomit.R | 6 +++--- tests/testthat/test-ordinalscore.R | 2 +- tests/testthat/test-profile.R | 2 +- tests/testthat/test-shuffle.R | 8 ++++---- 15 files changed, 37 insertions(+), 36 deletions(-) diff --git a/tests/testthat/_snaps/class.md b/tests/testthat/_snaps/class.md index c8cf04c3e..6d7f75ff1 100644 --- a/tests/testthat/_snaps/class.md +++ b/tests/testthat/_snaps/class.md @@ -122,7 +122,7 @@ predictor: 10 -- Operations - * Checking the class(es) for: everything() + * Checking the class(es) for: all_predictors() --- diff --git a/tests/testthat/_snaps/colcheck.md b/tests/testthat/_snaps/colcheck.md index 9fff9c3f4..b0b6c6870 100644 --- a/tests/testthat/_snaps/colcheck.md +++ b/tests/testthat/_snaps/colcheck.md @@ -1,7 +1,7 @@ # check_col works in the bake stage Code - rp1 %>% check_cols(everything()) %>% prep() %>% bake(mtcars[-1]) + rp1 %>% check_cols(all_predictors()) %>% prep() %>% bake(mtcars[-1]) Condition Error in `bake()`: x The following required columns are missing from `new_data`: `mpg`. @@ -65,7 +65,7 @@ predictor: 10 -- Operations - * Check if the following columns are present:: everything() + * Check if the following columns are present:: all_predictors() --- diff --git a/tests/testthat/_snaps/cut.md b/tests/testthat/_snaps/cut.md index 96489cc0a..643c23abe 100644 --- a/tests/testthat/_snaps/cut.md +++ b/tests/testthat/_snaps/cut.md @@ -11,7 +11,7 @@ --- Code - recipe(x) %>% step_cut(everything(), breaks = 2) %>% prep() + recipe(~., x) %>% step_cut(all_predictors(), breaks = 2) %>% prep() Condition Error in `step_cut()`: Caused by error in `prep()`: diff --git a/tests/testthat/_snaps/missing.md b/tests/testthat/_snaps/missing.md index 83f34f66d..890d84220 100644 --- a/tests/testthat/_snaps/missing.md +++ b/tests/testthat/_snaps/missing.md @@ -46,7 +46,7 @@ --- Code - tst(everything()) + tst(all_predictors()) Condition Error in `check_missing()`: Caused by error in `bake()`: diff --git a/tests/testthat/_snaps/profile.md b/tests/testthat/_snaps/profile.md index 60da65573..6561f30e5 100644 --- a/tests/testthat/_snaps/profile.md +++ b/tests/testthat/_snaps/profile.md @@ -1,7 +1,8 @@ # bad values Code - sacr_rec %>% step_profile(everything(), profile = vars(sqft)) %>% prep(data = Sacramento) + sacr_rec %>% step_profile(all_predictors(), profile = vars(sqft)) %>% prep( + data = Sacramento) Condition Error in `step_profile()`: Caused by error in `prep()`: diff --git a/tests/testthat/_snaps/shuffle.md b/tests/testthat/_snaps/shuffle.md index ecc37c00c..3dbd40d33 100644 --- a/tests/testthat/_snaps/shuffle.md +++ b/tests/testthat/_snaps/shuffle.md @@ -1,7 +1,7 @@ # bake a single row Code - dat4 <- bake(rec4, dat[1, ], everything()) + dat4 <- bake(rec4, dat[1, ]) Condition Warning: `new_data` contains a single row; unable to shuffle. @@ -55,7 +55,7 @@ predictor: 4 -- Operations - * Shuffled: everything() + * Shuffled: all_predictors() --- @@ -74,5 +74,5 @@ Training data contained 50 data points and no incomplete rows. -- Operations - * Shuffled: x1, x2, x3, x4, y | Trained + * Shuffled: x1, x2, x3, x4 | Trained diff --git a/tests/testthat/test-class.R b/tests/testthat/test-class.R index ada82a93e..b4de17dcd 100644 --- a/tests/testthat/test-class.R +++ b/tests/testthat/test-class.R @@ -29,8 +29,8 @@ test_that("bake_check_class helper function gives expected output", { }) test_that("check_class works when class is learned", { - rec1 <- recipe(x) %>% - check_class(everything()) %>% + rec1 <- recipe(~ ., x) %>% + check_class(all_predictors()) %>% prep() expect_error(bake(rec1, x), NA) @@ -76,7 +76,7 @@ test_that("check_class works when class is provided", { # recipes has internal coercion to character >> factor test_that("characters are handled correctly", { rec5_NULL <- recipe(Sacramento[1:10, ], sqft ~ .) %>% - check_class(everything()) %>% + check_class(all_predictors()) %>% prep(Sacramento[1:10, ], strings_as_factors = FALSE) expect_error(bake(rec5_NULL, Sacramento[11:20, ]), NA) @@ -96,7 +96,7 @@ test_that("characters are handled correctly", { ) rec6_NULL <- recipe(sacr_fac[1:10, ], sqft ~ .) %>% - check_class(everything()) %>% + check_class(all_predictors()) %>% prep(sacr_fac[1:10, ], strings_as_factors = TRUE) expect_snapshot(error = TRUE, @@ -165,7 +165,7 @@ test_that("empty selection tidy method works", { test_that("printing", { rec7 <- recipe(mpg ~ ., mtcars) %>% - check_class(everything()) + check_class(all_predictors()) expect_snapshot(print(rec7)) expect_snapshot(prep(rec7)) diff --git a/tests/testthat/test-colcheck.R b/tests/testthat/test-colcheck.R index 1c741799b..be64ecea5 100644 --- a/tests/testthat/test-colcheck.R +++ b/tests/testthat/test-colcheck.R @@ -5,8 +5,8 @@ rp1 <- recipe(mtcars, cyl ~ .) rp2 <- recipe(mtcars, cyl ~ mpg + drat) test_that("check_col works in the prep stage", { - expect_error(rp1 %>% check_cols(everything()) %>% prep(), NA) - expect_error(rp2 %>% check_cols(everything()) %>% prep(), NA) + expect_error(rp1 %>% check_cols(all_predictors()) %>% prep(), NA) + expect_error(rp2 %>% check_cols(all_predictors()) %>% prep(), NA) expect_error(rp2 %>% check_cols(cyl, mpg, drat) %>% prep(), NA) expect_error(rp2 %>% check_cols(cyl, mpg) %>% prep(), NA) }) @@ -14,20 +14,20 @@ test_that("check_col works in the prep stage", { test_that("check_col works in the bake stage", { - expect_error(rp1 %>% check_cols(everything()) %>% prep() %>% bake(mtcars), + expect_error(rp1 %>% check_cols(all_predictors()) %>% prep() %>% bake(mtcars), NA) - expect_equal(rp1 %>% check_cols(everything()) %>% prep() %>% bake(mtcars), + expect_equal(rp1 %>% check_cols(all_predictors()) %>% prep() %>% bake(mtcars), tibble(mtcars[ ,c(1, 3:11, 2)])) expect_error(rp2 %>% check_cols(cyl, mpg, drat) %>% prep %>% bake(mtcars), NA) expect_equal(rp2 %>% check_cols(cyl, mpg, drat) %>% prep %>% bake(mtcars), tibble(mtcars[ ,c(1, 5, 2)])) expect_error( - rp1 %>% check_cols(everything()) %>% prep() %>% bake(mtcars), + rp1 %>% check_cols(all_predictors()) %>% prep() %>% bake(mtcars), NA ) expect_equal( - rp1 %>% check_cols(everything()) %>% prep() %>% bake(mtcars), + rp1 %>% check_cols(all_predictors()) %>% prep() %>% bake(mtcars), tibble(mtcars[, c(1, 3:11, 2)]) ) expect_error(rp2 %>% check_cols(cyl, mpg, drat) %>% prep() %>% bake(mtcars), NA) @@ -36,7 +36,7 @@ test_that("check_col works in the bake stage", { tibble(mtcars[, c(1, 5, 2)]) ) expect_snapshot(error = TRUE, - rp1 %>% check_cols(everything()) %>% prep() %>% bake(mtcars[-1]) + rp1 %>% check_cols(all_predictors()) %>% prep() %>% bake(mtcars[-1]) ) expect_snapshot(error = TRUE, rp2 %>% check_cols(cyl, mpg, drat) %>% prep() %>% @@ -195,7 +195,7 @@ test_that("empty selection tidy method works", { test_that("printing", { rec <- recipe(mpg ~ ., mtcars) %>% - check_cols(everything()) + check_cols(all_predictors()) expect_snapshot(print(rec)) expect_snapshot(prep(rec)) diff --git a/tests/testthat/test-cut.R b/tests/testthat/test-cut.R index a4078b579..185a3cd8b 100644 --- a/tests/testthat/test-cut.R +++ b/tests/testthat/test-cut.R @@ -5,7 +5,7 @@ test_that("step_cut throws error on non-numerics", { recipe(x) %>% step_cut(cat_var, breaks = 2) %>% prep() ) expect_snapshot(error = TRUE, - recipe(x) %>% step_cut(everything(), breaks = 2) %>% prep() + recipe(~., x) %>% step_cut(all_predictors(), breaks = 2) %>% prep() ) }) diff --git a/tests/testthat/test-indicate_na.R b/tests/testthat/test-indicate_na.R index 2b362e480..950f26cf1 100644 --- a/tests/testthat/test-indicate_na.R +++ b/tests/testthat/test-indicate_na.R @@ -43,7 +43,7 @@ test_that("step_indicate_na populates binaries correctly", { test_that("step_indicate_na on all columns", { baked <- recipe(Ozone ~ ., data = airquality) %>% - step_indicate_na(everything()) %>% + step_indicate_na(all_predictors()) %>% prep(airquality, verbose = FALSE, retain = TRUE) %>% bake(new_data = NULL) @@ -52,7 +52,7 @@ test_that("step_indicate_na on all columns", { c( "Solar.R", "Wind", "Temp", "Month", "Day", "Ozone", "na_ind_Solar.R", "na_ind_Wind", "na_ind_Temp", - "na_ind_Month", "na_ind_Day", "na_ind_Ozone" + "na_ind_Month", "na_ind_Day" ) ) }) diff --git a/tests/testthat/test-missing.R b/tests/testthat/test-missing.R index 2b15e31d2..90be866ba 100644 --- a/tests/testthat/test-missing.R +++ b/tests/testthat/test-missing.R @@ -10,7 +10,7 @@ set_with_na <- tibble( tst <- function(...) { cols <- quos(...) - recipe(set_with_na) %>% + recipe(~ ., set_with_na) %>% check_missing(!!!cols) %>% prep() %>% bake(set_with_na) @@ -33,7 +33,7 @@ test_that("check_missing throws error on all types", { test_that("check_missing works on multiple columns simultaneously", { expect_snapshot(error = TRUE, tst(a, e)) - expect_snapshot(error = TRUE, tst(everything())) + expect_snapshot(error = TRUE, tst(all_predictors())) }) test_that("check_missing on a new set", { diff --git a/tests/testthat/test-naomit.R b/tests/testthat/test-naomit.R index 692e605aa..606a1ce4c 100644 --- a/tests/testthat/test-naomit.R +++ b/tests/testthat/test-naomit.R @@ -2,15 +2,15 @@ library(testthat) library(recipes) test_that("step_naomit on all columns", { - baked <- recipe(Ozone ~ ., data = airquality) %>% - step_naomit(everything()) %>% + baked <- recipe(~ ., data = airquality) %>% + step_naomit(all_predictors()) %>% prep(airquality, verbose = FALSE) %>% bake(new_data = NULL) na_res <- tibble(na.omit(airquality)) attributes(na_res)$na.action <- NULL - expect_equal(baked, na_res[, c(2:6, 1)]) + expect_equal(baked, na_res) }) test_that("step_naomit on subset of columns", { diff --git a/tests/testthat/test-ordinalscore.R b/tests/testthat/test-ordinalscore.R index 93e520527..e554c6765 100644 --- a/tests/testthat/test-ordinalscore.R +++ b/tests/testthat/test-ordinalscore.R @@ -65,7 +65,7 @@ test_that("nonlinear scores", { test_that("bad spec", { rec3 <- recipe(~., data = ex_dat) %>% - step_ordinalscore(everything()) + step_ordinalscore(all_predictors()) expect_snapshot(error = TRUE, prep(rec3, training = ex_dat, verbose = FALSE) ) diff --git a/tests/testthat/test-profile.R b/tests/testthat/test-profile.R index 374424ed4..e956df474 100644 --- a/tests/testthat/test-profile.R +++ b/tests/testthat/test-profile.R @@ -72,7 +72,7 @@ test_that("character profile", { test_that("bad values", { expect_snapshot(error = TRUE, sacr_rec %>% - step_profile(everything(), profile = vars(sqft)) %>% + step_profile(all_predictors(), profile = vars(sqft)) %>% prep(data = Sacramento) ) expect_snapshot(error = TRUE, diff --git a/tests/testthat/test-shuffle.R b/tests/testthat/test-shuffle.R index 62c0469a7..45d81ff2e 100644 --- a/tests/testthat/test-shuffle.R +++ b/tests/testthat/test-shuffle.R @@ -46,7 +46,7 @@ test_that("nominal data", { test_that("all data", { rec3 <- recipe(y ~ ., data = dat) %>% - step_shuffle(everything()) + step_shuffle(all_predictors()) rec3 <- prep(rec3, training = dat, verbose = FALSE) set.seed(2516) @@ -62,10 +62,10 @@ test_that("all data", { test_that("bake a single row", { rec4 <- recipe(y ~ ., data = dat) %>% - step_shuffle(everything()) + step_shuffle(all_predictors()) rec4 <- prep(rec4, training = dat, verbose = FALSE) - expect_snapshot(dat4 <- bake(rec4, dat[1, ], everything())) + expect_snapshot(dat4 <- bake(rec4, dat[1, ])) expect_equal(dat4, tibble(dat[1, ])) }) @@ -122,7 +122,7 @@ test_that("empty selection tidy method works", { test_that("printing", { rec <- recipe(y ~ ., data = dat) %>% - step_shuffle(everything()) + step_shuffle(all_predictors()) expect_snapshot(print(rec)) expect_snapshot(prep(rec))