diff --git a/DESCRIPTION b/DESCRIPTION index f516b23..c3fec82 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,6 +19,7 @@ Imports: Suggests: arrow, DBI, + data.table, dbplyr, dtplyr, duckdb, diff --git a/tests/testthat/_snaps/dt.new.md b/tests/testthat/_snaps/dt.new.md deleted file mode 100644 index 7e2bcbb..0000000 --- a/tests/testthat/_snaps/dt.new.md +++ /dev/null @@ -1,26 +0,0 @@ -# dt works - - Code - orbital_dt(obj) - Output - copy(`_DT2`)[, `:=`(c("cyl", "disp", "hp", "drat", "wt", "qsec", - "vs", "am", "gear", "carb", ".pred"), { - cyl <- (cyl - 6.1875)/1.785922 - disp <- (disp - 230.7219)/123.9387 - hp <- (hp - 146.6875)/68.56287 - drat <- (drat - 3.596562)/0.5346787 - wt <- (wt - 3.21725)/0.9784574 - qsec <- (qsec - 17.84875)/1.786943 - vs <- (vs - 0.4375)/0.5040161 - am <- (am - 0.40625)/0.4989909 - gear <- (gear - 3.6875)/0.7378041 - carb <- (carb - 2.8125)/1.6152 - .pred <- 20.09062 + (cyl * -0.199024) + (disp * - 1.652752) + (hp * -1.472876) + (drat * - 0.4208515) + (wt * -3.635267) + (qsec * - 1.467153) + (vs * 0.1601576) + (am * - 1.25757) + (gear * 0.4835664) + (carb * - -0.322102) - .(cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb, .pred) - })] - diff --git a/tests/testthat/test-step_adasyn.R b/tests/testthat/test-step_adasyn.R index b6ce049..df7868e 100644 --- a/tests/testthat/test-step_adasyn.R +++ b/tests/testthat/test-step_adasyn.R @@ -127,3 +127,27 @@ test_that("duckdb - step_adasyn works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_adasyn works", { + skip_if_not_installed("recipes") + skip_if_not_installed("themis") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_adasyn <- dplyr::as_tibble(mtcars) + mtcars_adasyn$vs <- as.factor(mtcars$vs) + + rec <- recipes::recipe(mpg ~ ., data = mtcars_adasyn) %>% + themis::step_adasyn(vs, skip = TRUE) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars_adasyn, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_adasyn) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_bin2factor.R b/tests/testthat/test-step_bin2factor.R index be0490a..de57ceb 100644 --- a/tests/testthat/test-step_bin2factor.R +++ b/tests/testthat/test-step_bin2factor.R @@ -119,3 +119,25 @@ test_that("duckdb - step_bin2factor works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_bin2factor works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars <- dplyr::as_tibble(mtcars) + + rec <- recipes::recipe(mpg ~ ., data = mtcars) %>% + recipes::step_bin2factor(vs, am) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_boxcox.R b/tests/testthat/test-step_boxcox.R index 9a4f8bd..8a4c017 100644 --- a/tests/testthat/test-step_boxcox.R +++ b/tests/testthat/test-step_boxcox.R @@ -117,3 +117,26 @@ test_that("duckdb - step_BoxCox works", { DBI::dbDisconnect(con) }) + + +test_that("data.table - step_BoxCox works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars <- dplyr::as_tibble(mtcars) + + rec <- recipes::recipe(~ ., data = mtcars) %>% + recipes::step_BoxCox(mpg, disp) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_bsmote.R b/tests/testthat/test-step_bsmote.R index e0dd5e9..d17d245 100644 --- a/tests/testthat/test-step_bsmote.R +++ b/tests/testthat/test-step_bsmote.R @@ -127,3 +127,27 @@ test_that("duckdb - step_bsmote works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_bsmote works", { + skip_if_not_installed("recipes") + skip_if_not_installed("themis") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_bsmote <- dplyr::as_tibble(mtcars) + mtcars_bsmote$vs <- as.factor(mtcars$vs) + + rec <- recipes::recipe(mpg ~ ., data = mtcars_bsmote) %>% + themis::step_bsmote(vs, skip = TRUE) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars_bsmote, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_bsmote) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_center.R b/tests/testthat/test-step_center.R index 3652ccf..58ae157 100644 --- a/tests/testthat/test-step_center.R +++ b/tests/testthat/test-step_center.R @@ -117,3 +117,25 @@ test_that("duckdb - step_center works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_center works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars <- dplyr::as_tibble(mtcars) + + rec <- recipes::recipe(mpg ~ ., data = mtcars) %>% + recipes::step_center(recipes::all_predictors()) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_corr.R b/tests/testthat/test-step_corr.R index 4be5ae9..0abf363 100644 --- a/tests/testthat/test-step_corr.R +++ b/tests/testthat/test-step_corr.R @@ -42,4 +42,9 @@ test_that("SQLite - step_corr works", { test_that("duckdb - step_corr works", { # Isn't needed as `step_corr()` doesn't produce code expect_true(TRUE) +}) + +test_that("data.table - step_corr works", { + # Isn't needed as `step_corr()` doesn't produce code + expect_true(TRUE) }) \ No newline at end of file diff --git a/tests/testthat/test-step_discretize.R b/tests/testthat/test-step_discretize.R index e8425ec..6ef321a 100644 --- a/tests/testthat/test-step_discretize.R +++ b/tests/testthat/test-step_discretize.R @@ -176,3 +176,28 @@ test_that("duckdb - step_discretize works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_discretize works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_discretize <- dplyr::as_tibble(mtcars) + mtcars_discretize[1, ] <- NA + + suppressWarnings( + rec <- recipes::recipe(mpg ~ ., data = mtcars_discretize) %>% + recipes::step_discretize(mpg, disp, min_unique = 4) %>% + recipes::prep() + ) + + res <- dplyr::mutate(mtcars_discretize, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_discretize) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_downsample.R b/tests/testthat/test-step_downsample.R index d6e34fe..73b86cb 100644 --- a/tests/testthat/test-step_downsample.R +++ b/tests/testthat/test-step_downsample.R @@ -127,3 +127,27 @@ test_that("duckdb - step_downsample works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_downsample works", { + skip_if_not_installed("recipes") + skip_if_not_installed("themis") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_downsample <- dplyr::as_tibble(mtcars) + mtcars_downsample$vs <- as.factor(mtcars$vs) + + rec <- recipes::recipe(mpg ~ ., data = mtcars_downsample) %>% + themis::step_downsample(vs, skip = TRUE) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars_downsample, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_downsample) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_dummy.R b/tests/testthat/test-step_dummy.R index 69a2cc3..0fe069a 100644 --- a/tests/testthat/test-step_dummy.R +++ b/tests/testthat/test-step_dummy.R @@ -153,4 +153,29 @@ test_that("duckdb - step_dummy works", { expect_equal(res_new, exp) DBI::dbDisconnect(con) +}) + +test_that("data.table - step_dummy works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars1 <- dplyr::as_tibble(mtcars) + + mtcars1$gear <- as.character(mtcars1$gear) + mtcars1$carb <- as.character(mtcars1$carb) + + rec <- recipes::recipe(mpg ~ ., data = mtcars1) %>% + recipes::step_dummy(recipes::all_nominal_predictors()) %>% + recipes::prep() + + exp <- dplyr::mutate(mtcars1, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars1) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, exp) }) \ No newline at end of file diff --git a/tests/testthat/test-step_filter_missing.R b/tests/testthat/test-step_filter_missing.R index 3ff974c..6c11dc7 100644 --- a/tests/testthat/test-step_filter_missing.R +++ b/tests/testthat/test-step_filter_missing.R @@ -41,4 +41,9 @@ test_that("SQLite - step_filter_missing works", { test_that("duckdb - step_filter_missing works", { # Isn't needed as `step_filter_missing()` doesn't produce code expect_true(TRUE) +}) + +test_that("data.table - step_filter_missing works", { + # Isn't needed as `step_filter_missing()` doesn't produce code + expect_true(TRUE) }) \ No newline at end of file diff --git a/tests/testthat/test-step_impute_mean.R b/tests/testthat/test-step_impute_mean.R index 26a86d4..8f5f52c 100644 --- a/tests/testthat/test-step_impute_mean.R +++ b/tests/testthat/test-step_impute_mean.R @@ -122,3 +122,26 @@ test_that("duckdb - step_impute_mean works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_impute_mean works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_impute_mean <- dplyr::as_tibble(mtcars) + mtcars_impute_mean[2:4, ] <- NA + + rec <- recipes::recipe(mpg ~ ., data = mtcars_impute_mean) %>% + recipes::step_impute_mean(recipes::all_predictors()) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars_impute_mean, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_impute_mean) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_impute_median.R b/tests/testthat/test-step_impute_median.R index f649052..ec4a253 100644 --- a/tests/testthat/test-step_impute_median.R +++ b/tests/testthat/test-step_impute_median.R @@ -123,3 +123,26 @@ test_that("duckdb - step_impute_median works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_impute_median works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_impute_median <- dplyr::as_tibble(mtcars) + mtcars_impute_median[2:4, ] <- NA + + rec <- recipes::recipe(mpg ~ ., data = mtcars_impute_median) %>% + recipes::step_impute_median(recipes::all_predictors()) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars_impute_median, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_impute_median) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_impute_mode.R b/tests/testthat/test-step_impute_mode.R index 8d35e43..6ea0710 100644 --- a/tests/testthat/test-step_impute_mode.R +++ b/tests/testthat/test-step_impute_mode.R @@ -135,3 +135,28 @@ test_that("duckdb - step_impute_mode works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_impute_mode works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_impute_mode <- dplyr::as_tibble(mtcars) + mtcars_impute_mode$gear <- letters[mtcars$gear] + mtcars_impute_mode$carb <- letters[mtcars$carb] + mtcars_impute_mode[2:4, ] <- NA + + rec <- recipes::recipe(mpg ~ ., data = mtcars_impute_mode) %>% + recipes::step_impute_mode(recipes::all_nominal_predictors()) %>% + recipes::prep(strings_as_factors = FALSE) + + res <- dplyr::mutate(mtcars_impute_mode, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_impute_mode) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_indicate_na.R b/tests/testthat/test-step_indicate_na.R index 4fcda92..38363f1 100644 --- a/tests/testthat/test-step_indicate_na.R +++ b/tests/testthat/test-step_indicate_na.R @@ -126,3 +126,26 @@ test_that("duckdb - step_indicate_na works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_indicate_na works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_indicate_na <- dplyr::as_tibble(mtcars) + mtcars_indicate_na[2:4, ] <- NA + + rec <- recipes::recipe(mpg ~ ., data = mtcars_indicate_na) %>% + recipes::step_indicate_na(recipes::all_predictors()) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars_indicate_na, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_indicate_na) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_intercept.R b/tests/testthat/test-step_intercept.R index d384f0c..a9e318a 100644 --- a/tests/testthat/test-step_intercept.R +++ b/tests/testthat/test-step_intercept.R @@ -107,3 +107,25 @@ test_that("duckdb - step_intercept works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_intercept works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars <- dplyr::as_tibble(mtcars) + + rec <- recipes::recipe(mpg ~ ., data = mtcars) %>% + recipes::step_intercept(value = 5) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_inverse.R b/tests/testthat/test-step_inverse.R index 46b4709..d70a1df 100644 --- a/tests/testthat/test-step_inverse.R +++ b/tests/testthat/test-step_inverse.R @@ -134,3 +134,25 @@ test_that("duckdb - step_inverse works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_inverse works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars <- dplyr::as_tibble(mtcars) + + rec <- recipes::recipe(mpg ~ ., data = mtcars) %>% + recipes::step_inverse(recipes::all_predictors(), offset = 0.01) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_lag.R b/tests/testthat/test-step_lag.R index 91fe183..3ffa7a8 100644 --- a/tests/testthat/test-step_lag.R +++ b/tests/testthat/test-step_lag.R @@ -102,4 +102,26 @@ test_that("duckdb - step_lag works", { expect_equal(res_new, res) DBI::dbDisconnect(con) +}) + +test_that("data.table - step_lag works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars <- dplyr::as_tibble(mtcars) + + rec <- recipes::recipe(mpg ~ ., data = mtcars) %>% + recipes::step_lag(recipes::all_predictors(), lag = 1:4) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) }) \ No newline at end of file diff --git a/tests/testthat/test-step_lencode_bayes.R b/tests/testthat/test-step_lencode_bayes.R index 9ed9105..743013f 100644 --- a/tests/testthat/test-step_lencode_bayes.R +++ b/tests/testthat/test-step_lencode_bayes.R @@ -150,3 +150,30 @@ test_that("duckdb - step_lencode_bayes works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_lencode_bayes works", { + skip_if_not_installed("recipes") + skip_if_not_installed("rstanarm") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_lencode_bayes <- dplyr::as_tibble(mtcars) + mtcars_lencode_bayes$gear <- as.factor(mtcars_lencode_bayes$gear) + mtcars_lencode_bayes$vs <- as.factor(mtcars_lencode_bayes$vs) + + suppressWarnings( + rec <- recipes::recipe(mpg ~ ., data = mtcars_lencode_bayes) %>% + embed::step_lencode_bayes(gear, vs, outcome = dplyr::vars(mpg)) %>% + recipes::prep() + ) + + res <- dplyr::mutate(mtcars_lencode_bayes, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_lencode_bayes) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_lencode_glm.R b/tests/testthat/test-step_lencode_glm.R index 4260ed8..cf6dcfd 100644 --- a/tests/testthat/test-step_lencode_glm.R +++ b/tests/testthat/test-step_lencode_glm.R @@ -144,3 +144,29 @@ test_that("duckdb - step_lencode_glm works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_lencode_glm works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_lencode_glm <- dplyr::as_tibble(mtcars) + mtcars_lencode_glm$gear <- as.factor(mtcars_lencode_glm$gear) + mtcars_lencode_glm$vs <- as.factor(mtcars_lencode_glm$vs) + + suppressWarnings( + rec <- recipes::recipe(mpg ~ ., data = mtcars_lencode_glm) %>% + embed::step_lencode_glm(gear, vs, outcome = dplyr::vars(mpg)) %>% + recipes::prep() + ) + + res <- dplyr::mutate(mtcars_lencode_glm, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_lencode_glm) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_lencode_mixed.R b/tests/testthat/test-step_lencode_mixed.R index 76e4f43..db7aea7 100644 --- a/tests/testthat/test-step_lencode_mixed.R +++ b/tests/testthat/test-step_lencode_mixed.R @@ -144,3 +144,29 @@ test_that("duckdb - step_lencode_mixed works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_lencode_mixed works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_lencode_mixed <- dplyr::as_tibble(mtcars) + mtcars_lencode_mixed$gear <- as.factor(mtcars_lencode_mixed$gear) + mtcars_lencode_mixed$vs <- as.factor(mtcars_lencode_mixed$vs) + + suppressWarnings( + rec <- recipes::recipe(mpg ~ ., data = mtcars_lencode_mixed) %>% + embed::step_lencode_mixed(gear, vs, outcome = dplyr::vars(mpg)) %>% + recipes::prep() + ) + + res <- dplyr::mutate(mtcars_lencode_mixed, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_lencode_mixed) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_lincomb.R b/tests/testthat/test-step_lincomb.R index 0ab2c5d..86e235a 100644 --- a/tests/testthat/test-step_lincomb.R +++ b/tests/testthat/test-step_lincomb.R @@ -42,4 +42,9 @@ test_that("SQLite - step_lincomb works", { test_that("duckdb - step_lincomb works", { # Isn't needed as `step_lincomb()` doesn't produce code expect_true(TRUE) +}) + +test_that("data.table - step_lincomb works", { + # Isn't needed as `step_lincomb()` doesn't produce code + expect_true(TRUE) }) \ No newline at end of file diff --git a/tests/testthat/test-step_log.R b/tests/testthat/test-step_log.R index 3fc83e4..37783f6 100644 --- a/tests/testthat/test-step_log.R +++ b/tests/testthat/test-step_log.R @@ -134,3 +134,26 @@ test_that("duckdb - step_log works", { DBI::dbDisconnect(con) }) + + +test_that("data.table - step_log works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars <- dplyr::as_tibble(mtcars) + + rec <- recipes::recipe(mpg ~ ., data = mtcars) %>% + recipes::step_log(recipes::all_predictors(), offset = 0.5) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_mutate.R b/tests/testthat/test-step_mutate.R index cbc87c6..d683d4c 100644 --- a/tests/testthat/test-step_mutate.R +++ b/tests/testthat/test-step_mutate.R @@ -117,3 +117,25 @@ test_that("duckdb - step_mutate works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_mutate works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars <- dplyr::as_tibble(mtcars) + + rec <- recipes::recipe(mpg ~ ., data = mtcars) %>% + recipes::step_mutate(mpg = mpg + 5, disp4 = disp / 4) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_nearmiss.R b/tests/testthat/test-step_nearmiss.R index fd129d4..0c47805 100644 --- a/tests/testthat/test-step_nearmiss.R +++ b/tests/testthat/test-step_nearmiss.R @@ -127,3 +127,27 @@ test_that("duckdb - step_nearmiss works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_nearmiss works", { + skip_if_not_installed("recipes") + skip_if_not_installed("themis") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_nearmiss <- dplyr::as_tibble(mtcars) + mtcars_nearmiss$vs <- as.factor(mtcars$vs) + + rec <- recipes::recipe(mpg ~ ., data = mtcars_nearmiss) %>% + themis::step_nearmiss(vs, skip = TRUE) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars_nearmiss, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_nearmiss) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_normalize.R b/tests/testthat/test-step_normalize.R index d696507..7c5942b 100644 --- a/tests/testthat/test-step_normalize.R +++ b/tests/testthat/test-step_normalize.R @@ -117,3 +117,25 @@ test_that("duckdb - step_normalize works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_normalize works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars <- dplyr::as_tibble(mtcars) + + rec <- recipes::recipe(mpg ~ ., data = mtcars) %>% + recipes::step_normalize(recipes::all_predictors()) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_novel.R b/tests/testthat/test-step_novel.R index 6d02ec5..0989dc4 100644 --- a/tests/testthat/test-step_novel.R +++ b/tests/testthat/test-step_novel.R @@ -150,3 +150,30 @@ test_that("duckdb - step_novel works", { DBI::dbDisconnect(con) }) +test_that("data.table - step_novel works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_novel <- dplyr::as_tibble(mtcars) + mtcars_novel$gear <- letters[mtcars$gear] + mtcars_novel$carb <- letters[mtcars$carb] + mtcars_novel[2:4, ] <- NA + + rec <- recipes::recipe(mpg ~ ., data = mtcars_novel) %>% + recipes::step_novel(recipes::all_nominal_predictors()) %>% + recipes::prep() + + mtcars_novel[1, 10] <- "aaaaa" + + res <- dplyr::mutate(mtcars_novel, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_novel) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) + diff --git a/tests/testthat/test-step_nzv.R b/tests/testthat/test-step_nzv.R index 178c0e9..24e389b 100644 --- a/tests/testthat/test-step_nzv.R +++ b/tests/testthat/test-step_nzv.R @@ -42,4 +42,9 @@ test_that("SQLite - step_nzv works", { test_that("duckdb - step_nzv works", { # Isn't needed as `step_nzv()` doesn't produce code expect_true(TRUE) +}) + +test_that("data.table - step_nzv works", { + # Isn't needed as `step_nzv()` doesn't produce code + expect_true(TRUE) }) \ No newline at end of file diff --git a/tests/testthat/test-step_other.R b/tests/testthat/test-step_other.R index 478cfc3..7e6e7f3 100644 --- a/tests/testthat/test-step_other.R +++ b/tests/testthat/test-step_other.R @@ -151,3 +151,30 @@ test_that("duckdb - step_other works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_other works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_other <- dplyr::as_tibble(mtcars) + mtcars_other$gear <- letters[mtcars$gear] + mtcars_other$carb <- letters[mtcars$carb] + mtcars_other[2:4, ] <- NA + mtcars_other$gear[1] <- "aa" + mtcars_other$carb[1] <- "aa" + + rec <- recipes::recipe(mpg ~ ., data = mtcars_other) %>% + recipes::step_other(recipes::all_nominal_predictors()) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars_other, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_other) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_pca.R b/tests/testthat/test-step_pca.R index f613738..9378241 100644 --- a/tests/testthat/test-step_pca.R +++ b/tests/testthat/test-step_pca.R @@ -139,4 +139,27 @@ test_that("duckdb - step_pca works", { expect_equal(res_new, res) DBI::dbDisconnect(con) +}) + +test_that("data.table - step_pca works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars0 <- dplyr::as_tibble(mtcars) + mtcars0$hp <- NULL + + rec <- recipes::recipe(mpg ~ ., data = mtcars0) %>% + recipes::step_pca(recipes::all_predictors()) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars0, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars0) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) }) \ No newline at end of file diff --git a/tests/testthat/test-step_pca_sparse.R b/tests/testthat/test-step_pca_sparse.R index 3e5bae9..aa118a4 100644 --- a/tests/testthat/test-step_pca_sparse.R +++ b/tests/testthat/test-step_pca_sparse.R @@ -159,4 +159,30 @@ test_that("duckdb - step_pca_sparse works", { expect_equal(res_new, exp) DBI::dbDisconnect(con) +}) + +test_that("data.table - step_pca_sparse works", { + skip_if_not_installed("recipes") + skip_if_not_installed("embed") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars0 <- dplyr::as_tibble(mtcars) + mtcars0$hp <- NULL + + suppressWarnings( + rec <- recipes::recipe(mpg ~ ., data = mtcars0) %>% + embed::step_pca_sparse(recipes::all_predictors()) %>% + recipes::prep() + ) + + exp <- dplyr::mutate(mtcars0, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars0) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, exp) }) \ No newline at end of file diff --git a/tests/testthat/test-step_pca_sparse_bayes.R b/tests/testthat/test-step_pca_sparse_bayes.R index 4373769..9dd5f6d 100644 --- a/tests/testthat/test-step_pca_sparse_bayes.R +++ b/tests/testthat/test-step_pca_sparse_bayes.R @@ -166,3 +166,30 @@ test_that("duckdb - step_pca_sparse_bayes works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_pca_sparse_bayes works", { + skip_if_not_installed("recipes") + skip_if_not_installed("embed") + skip_if_not_installed("VBsparsePCA") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars0 <- dplyr::as_tibble(mtcars) + mtcars0$hp <- NULL + + suppressWarnings( + rec <- recipes::recipe(mpg ~ ., data = mtcars0) %>% + embed::step_pca_sparse_bayes(recipes::all_predictors()) %>% + recipes::prep() + ) + + exp <- dplyr::mutate(mtcars0, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars0) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, exp) +}) diff --git a/tests/testthat/test-step_pca_truncated.R b/tests/testthat/test-step_pca_truncated.R index 4a3744e..0add633 100644 --- a/tests/testthat/test-step_pca_truncated.R +++ b/tests/testthat/test-step_pca_truncated.R @@ -157,4 +157,30 @@ test_that("duckdb - step_pca_truncated works", { expect_equal(res_new, exp) DBI::dbDisconnect(con) +}) + +test_that("data.table - step_pca_truncated works", { + skip_if_not_installed("recipes") + skip_if_not_installed("embed") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars0 <- dplyr::as_tibble(mtcars) + mtcars0$hp <- NULL + + suppressWarnings( + rec <- recipes::recipe(mpg ~ ., data = mtcars0) %>% + embed::step_pca_truncated(recipes::all_predictors()) %>% + recipes::prep() + ) + + exp <- dplyr::mutate(mtcars0, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars0) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, exp) }) \ No newline at end of file diff --git a/tests/testthat/test-step_range.R b/tests/testthat/test-step_range.R index 943a0e8..6d8c89b 100644 --- a/tests/testthat/test-step_range.R +++ b/tests/testthat/test-step_range.R @@ -138,3 +138,27 @@ test_that("duckdb - step_range works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_range works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars <- dplyr::as_tibble(mtcars) + + rec <- recipes::recipe(mpg ~ ., data = mtcars) %>% + recipes::step_range(recipes::all_predictors()) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars) + + suppressWarnings( + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + ) + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_ratio.R b/tests/testthat/test-step_ratio.R index 0799734..4628118 100644 --- a/tests/testthat/test-step_ratio.R +++ b/tests/testthat/test-step_ratio.R @@ -124,3 +124,26 @@ test_that("duckdb - step_ratio works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_ratio works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars <- dplyr::as_tibble(mtcars) + + rec <- recipes::recipe(mpg ~ ., data = mtcars) %>% + recipes::step_ratio(recipes::all_predictors(), + denom = recipes::denom_vars(disp)) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_rename.R b/tests/testthat/test-step_rename.R index 132d627..d553105 100644 --- a/tests/testthat/test-step_rename.R +++ b/tests/testthat/test-step_rename.R @@ -117,3 +117,26 @@ test_that("duckdb - step_rename works", { DBI::dbDisconnect(con) }) + + +test_that("data.table - step_rename works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars <- dplyr::as_tibble(mtcars) + + rec <- recipes::recipe(mpg ~ ., data = mtcars) %>% + recipes::step_rename(mpg3 = mpg, aaa = disp) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_rm.R b/tests/testthat/test-step_rm.R index 03998ad..9db33a4 100644 --- a/tests/testthat/test-step_rm.R +++ b/tests/testthat/test-step_rm.R @@ -42,4 +42,9 @@ test_that("SQLite - step_rm works", { test_that("duckdb - step_rm works", { # Isn't needed as `step_zv()` doesn't produce code expect_true(TRUE) +}) + +test_that("data.table - step_rm works", { + # Isn't needed as `step_zv()` doesn't produce code + expect_true(TRUE) }) \ No newline at end of file diff --git a/tests/testthat/test-step_rose.R b/tests/testthat/test-step_rose.R index 0778acb..8a55b61 100644 --- a/tests/testthat/test-step_rose.R +++ b/tests/testthat/test-step_rose.R @@ -127,3 +127,27 @@ test_that("duckdb - step_rose works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_rose works", { + skip_if_not_installed("recipes") + skip_if_not_installed("themis") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_rose <- dplyr::as_tibble(mtcars) + mtcars_rose$vs <- as.factor(mtcars$vs) + + rec <- recipes::recipe(mpg ~ ., data = mtcars_rose) %>% + themis::step_rose(vs, skip = TRUE) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars_rose, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_rose) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_scale.R b/tests/testthat/test-step_scale.R index 7f7e464..c352eee 100644 --- a/tests/testthat/test-step_scale.R +++ b/tests/testthat/test-step_scale.R @@ -117,3 +117,25 @@ test_that("duckdb - step_scale works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_scale works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars <- dplyr::as_tibble(mtcars) + + rec <- recipes::recipe(mpg ~ ., data = mtcars) %>% + recipes::step_scale(recipes::all_predictors()) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_select.R b/tests/testthat/test-step_select.R index 6d34c60..21c7281 100644 --- a/tests/testthat/test-step_select.R +++ b/tests/testthat/test-step_select.R @@ -42,4 +42,9 @@ test_that("SQLite - step_select works", { test_that("duckdb - step_select works", { # Isn't needed as `step_select()` doesn't produce code expect_true(TRUE) +}) + +test_that("data.table - step_select works", { + # Isn't needed as `step_select()` doesn't produce code + expect_true(TRUE) }) \ No newline at end of file diff --git a/tests/testthat/test-step_smote.R b/tests/testthat/test-step_smote.R index f442c98..e26e796 100644 --- a/tests/testthat/test-step_smote.R +++ b/tests/testthat/test-step_smote.R @@ -127,3 +127,27 @@ test_that("duckdb - step_smote works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_smote works", { + skip_if_not_installed("recipes") + skip_if_not_installed("themis") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_smote <- dplyr::as_tibble(mtcars) + mtcars_smote$vs <- as.factor(mtcars$vs) + + rec <- recipes::recipe(mpg ~ ., data = mtcars_smote) %>% + themis::step_smote(vs, skip = TRUE) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars_smote, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_smote) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_smotenc.R b/tests/testthat/test-step_smotenc.R index f0f6dd8..fc900ed 100644 --- a/tests/testthat/test-step_smotenc.R +++ b/tests/testthat/test-step_smotenc.R @@ -127,3 +127,27 @@ test_that("duckdb - step_smotenc works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_smotenc works", { + skip_if_not_installed("recipes") + skip_if_not_installed("themis") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_smotenc <- dplyr::as_tibble(mtcars) + mtcars_smotenc$vs <- as.factor(mtcars$vs) + + rec <- recipes::recipe(mpg ~ ., data = mtcars_smotenc) %>% + themis::step_smotenc(vs, skip = TRUE) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars_smotenc, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_smotenc) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_sqrt.R b/tests/testthat/test-step_sqrt.R index ad06926..6301aaa 100644 --- a/tests/testthat/test-step_sqrt.R +++ b/tests/testthat/test-step_sqrt.R @@ -94,10 +94,11 @@ test_that("SQLite - step_sqrt works", { DBI::dbDisconnect(con) }) -test_that("duckdb - step_sqrt works", { +test_that("data.table - step_sqrt works", { skip_if_not_installed("recipes") - skip_if_not_installed("DBI") - skip_if_not_installed("duckdb") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` mtcars <- dplyr::as_tibble(mtcars) @@ -107,13 +108,10 @@ test_that("duckdb - step_sqrt works", { res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec))) - con <- DBI::dbConnect(duckdb::duckdb(dbdir = ":memory:")) - mtcars_tbl <- dplyr::copy_to(con, mtcars) + mtcars_tbl <- dtplyr::lazy_dt(mtcars) res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% dplyr::collect() expect_equal(res_new, res) - - DBI::dbDisconnect(con) }) diff --git a/tests/testthat/test-step_tomek.R b/tests/testthat/test-step_tomek.R index 470b3e2..73912b7 100644 --- a/tests/testthat/test-step_tomek.R +++ b/tests/testthat/test-step_tomek.R @@ -127,3 +127,27 @@ test_that("duckdb - step_tomek works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_tomek works", { + skip_if_not_installed("recipes") + skip_if_not_installed("themis") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_tomek <- dplyr::as_tibble(mtcars) + mtcars_tomek$vs <- as.factor(mtcars$vs) + + rec <- recipes::recipe(mpg ~ ., data = mtcars_tomek) %>% + themis::step_tomek(vs, skip = TRUE) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars_tomek, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_tomek) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_unknown.R b/tests/testthat/test-step_unknown.R index 7b28157..385b008 100644 --- a/tests/testthat/test-step_unknown.R +++ b/tests/testthat/test-step_unknown.R @@ -139,3 +139,28 @@ test_that("duckdb - step_unknown works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_unknown works", { + skip_if_not_installed("recipes") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_unknown <- dplyr::as_tibble(mtcars) + mtcars_unknown$gear <- letters[mtcars$gear] + mtcars_unknown$carb <- letters[mtcars$carb] + mtcars_unknown[2:4, ] <- NA + + rec <- recipes::recipe(mpg ~ ., data = mtcars_unknown) %>% + recipes::step_unknown(recipes::all_nominal_predictors()) %>% + recipes::prep(strings_as_factors = FALSE) + + res <- dplyr::mutate(mtcars_unknown, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_unknown) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_upsample.R b/tests/testthat/test-step_upsample.R index 49bed37..ed308bd 100644 --- a/tests/testthat/test-step_upsample.R +++ b/tests/testthat/test-step_upsample.R @@ -127,3 +127,27 @@ test_that("duckdb - step_upsample works", { DBI::dbDisconnect(con) }) + +test_that("data.table - step_upsample works", { + skip_if_not_installed("recipes") + skip_if_not_installed("themis") + skip_if_not_installed("dtplyr") + + `:=` <- data.table::`:=` + + mtcars_upsample <- dplyr::as_tibble(mtcars) + mtcars_upsample$vs <- as.factor(mtcars$vs) + + rec <- recipes::recipe(mpg ~ ., data = mtcars_upsample) %>% + themis::step_upsample(vs, skip = TRUE) %>% + recipes::prep() + + res <- dplyr::mutate(mtcars_upsample, !!!orbital_inline(orbital(rec))) + + mtcars_tbl <- dtplyr::lazy_dt(mtcars_upsample) + + res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>% + dplyr::collect() + + expect_equal(res_new, res) +}) diff --git a/tests/testthat/test-step_zv.R b/tests/testthat/test-step_zv.R index 2ac4e28..e113015 100644 --- a/tests/testthat/test-step_zv.R +++ b/tests/testthat/test-step_zv.R @@ -43,3 +43,8 @@ test_that("duckdb - step_zv works", { # Isn't needed as `step_zv()` doesn't produce code expect_true(TRUE) }) + +test_that("data.table - step_zv works", { + # Isn't needed as `step_zv()` doesn't produce code + expect_true(TRUE) +})