tests/testthat/test-recipes.R

test_that("recipe works", {
	skip_if_not_installed("recipes")
	skip_if_not_installed("parsnip")
	skip_if_not_installed("workflows")
	skip_if_not_installed("tidypredict")

	rec_spec <- recipes::recipe(mpg ~ ., data = mtcars) %>%
		recipes::step_impute_knn(recipes::all_numeric_predictors())

	lm_spec <- parsnip::linear_reg()

	wf_spec <- workflows::workflow(rec_spec, lm_spec)

	wf_fit <- parsnip::fit(wf_spec, mtcars)

	expect_snapshot(
		error = TRUE,
		orbital(wf_fit)
	)
})

test_that("recipe works with skip argument", {
	skip_if_not_installed("recipes")
	skip_if_not_installed("parsnip")
	skip_if_not_installed("workflows")
	skip_if_not_installed("tidypredict")

	mtcars <- dplyr::as_tibble(mtcars)

	rec <- recipes::recipe(mpg ~ ., data = mtcars) %>%
		recipes::step_center(recipes::all_predictors(), skip = TRUE) %>%
		recipes::step_scale(recipes::all_predictors()) %>%
		recipes::prep()

	res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec)))

	exp <- recipes::bake(rec, new_data = mtcars)
	exp <- exp[names(res)]

	expect_equal(res, exp)
})

test_that("prefix argument works", {
	skip_if_not_installed("recipes")

	rec_spec <- recipes::recipe(mpg ~ ., data = mtcars) %>%
		recipes::step_normalize(recipes::all_numeric_predictors())

	rec_fit <- recipes::prep(rec_spec)

	orb_obj <- orbital(rec_fit, prefix = "pred")

	expect_false("pred" %in% names(orb_obj))
	expect_false(".pred" %in% names(orb_obj))
})

Try the orbital package in your browser

Any scripts or data that you put into this service are public.

orbital documentation built on April 3, 2025, 8:47 p.m.