`prep(rec)` did not throw the expected error.

test_that("dummy variables with factor inputs", {
rec <- recipe(sqft ~ zip + city, data = sacr_fac)
dummy <- rec %>% step_dummy(city, zip, id = "")
dummy_trained <- prep(dummy, training = sacr_fac, verbose = FALSE, strings_as_factors = FALSE)
dummy_pred <- bake(dummy_trained, new_data = sacr_fac, all_predictors())
exp_res <- model.matrix(sqft ~ zip + city, data = sacr_fac)[, -1]
exp_res <- exp_res[, colnames(exp_res) != "sqft"]
colnames(exp_res) <- gsub("^zip", "zip_", colnames(exp_res))
colnames(exp_res) <- gsub("^city", "city_", colnames(exp_res))
expect_equal(dummy_pred, exp_res, ignore_attr = TRUE)
tibble(terms = c("city", "zip"), columns = rep(rlang::na_chr, 2), id = "")
test_that("dummy variables errors with character inputs", {
rec <- recipe(sqft ~ zip + city, data = sacr)
prep(dummy, training = sacr, verbose = FALSE, strings_as_factors = FALSE)
recipe(sqft ~ zip + price + city, data = sacr) %>%
test_that("create double dummy variables", {
test_that("create all dummy variables", {
rec <- recipe(sqft ~ zip + city + price, data = sacr_fac)
dummy <- rec %>% step_dummy(city, zip, one_hot = TRUE, id = "")
for (pred in c("city", "price", "zip")) {
tmp <- model.matrix(as.formula(paste("~", pred, "+ 0")), data = sacr_fac)
colnames(tmp) <- gsub(paste0("^", pred), paste0(pred, "_"), colnames(tmp))
# expect_equal(dummy_pred, exp_res, ignore_attr = TRUE)
factors <- prep(factors, training = sacr)
factors_data_1 <- bake(factors, new_data = sacr)
factors_data_2 <- bake(factors, new_data = sacr %>% filter(city != "SACRAMENTO"))
rec <- recipe(~ordered_city, data = sacr)
orderedfac <- rec %>% step_dummy(ordered_city)
orderedfac <- prep(orderedfac, training = sacr)
ordered_data_1 <- bake(orderedfac, new_data = sacr)
ordered_data_2 <- bake(orderedfac, new_data = sacr %>% filter(city != "SACRAMENTO"))
test_that("tests for NA values in factor", {
rec <- recipe(~city, data = sacr_missing)
factors <- prep(factors, training = sacr_missing)
factors_data_0 <- bake(factors, new_data = NULL)
factors_data_1 <- bake(factors, new_data = sacr_missing)
test_that("tests for NA values in ordered factor", {
rec <- recipe(~city, data = sacr_ordered)
factors <- prep(factors, training = sacr_ordered)
factors_data_1 <- bake(factors, new_data = sacr_ordered)
rec <- recipe(y ~ x1, data = training) %>%
test_that("warns about NA in column (#450)", {
dummies <- prep(dummies, training = iris)
read_recipe <- readRDS(file = saved_recipe)
expect_equal(bake(dummies, new_data = iris), bake(read_recipe, new_data = iris))
expect_equal(bake(dummies, new_data = iris), bake(saved_dummies, new_data = iris))
test_that("works with non-standard column names", {
df <- tibble(`with space` = factor(letters[1:3]))
step_dummy(all_predictors(), one_hot = TRUE) %>%
c("with space_a", "with space_b", "with space_c")
expect_equal(dummy_names("x", letters[1:3]), c("x_a", "x_b", "x_c"))
dummy_names("x", letters[1:3], ordinal = TRUE),
exp_tidy <- tibble(terms = character(), columns = character(), id = character())
expect_equal(exp_tidy, tidy(rec, number = 2))
test_that("throws a informative error for too many levels (#828)", {
dat <- data.frame(x = as.character(1:123456))
test_that("bake method errors when needed non-standard role columns are missing", {
dummy <- rec %>% step_dummy(city, zip, id = "") %>%
update_role(city, zip, new_role = "potato") %>%
update_role_requirements(role = "potato", bake = FALSE)
expect_error(bake(dummy_trained, new_data = sacr_fac[, 3:4], all_predictors()),
test_that("empty selection prep/bake is a no-op", {
test_that("empty selection tidy method works", {
expect <- tibble(terms = character(), columns = character(), id = character())
expect_identical(tidy(rec, number = 1), expect)
test_that("keep_original_cols - can prep recipes with it missing", {
rec <- recipe(sqft ~ ., data = sacr_fac) %>%