# NOT RUN {
library(dplyr)
library(modeldata)
data(okc)
# Learn the classes on the train set
train <- okc[1:1000, ]
test <- okc[1001:2000, ]
recipe(train, age ~ . ) %>%
check_class(everything()) %>%
prep(train, strings_as_factors = FALSE) %>%
bake(test)
# Manual specification
recipe(train, age ~ .) %>%
check_class(age, class_nm = "integer") %>%
check_class(diet, location, class_nm = "character") %>%
check_class(date, class_nm = "Date") %>%
prep(train, strings_as_factors = FALSE) %>%
bake(test)
# By default only the classes that are specified
# are allowed.
x_df <- tibble(time = c(Sys.time() - 60, Sys.time()))
x_df$time %>% class()
# }
# NOT RUN {
recipe(x_df) %>%
check_class(time, class_nm = "POSIXt") %>%
prep(x_df) %>%
bake_(x_df)
# }
# NOT RUN {
# Use allow_additional = TRUE if you are fine with it
recipe(x_df) %>%
check_class(time, class_nm = "POSIXt", allow_additional = TRUE) %>%
prep(x_df) %>%
bake(x_df)
# }
Run the code above in your browser using DataLab