From bd2d0561e61922078e0e1ea21c0cb77cf54ed90e Mon Sep 17 00:00:00 2001 From: Tyson Barrett Date: Sun, 7 Jan 2024 13:50:08 -0700 Subject: [PATCH] Fix issue with data.table 1.15.0 Closes #52 --- tests/testthat/test-tidyfast.R | 55 ++++++++++++++-------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/tests/testthat/test-tidyfast.R b/tests/testthat/test-tidyfast.R index f1486b4..8f8985d 100644 --- a/tests/testthat/test-tidyfast.R +++ b/tests/testthat/test-tidyfast.R @@ -138,51 +138,42 @@ test_that("dt_uncount works", { }) test_that("dt_separate works", { - dt <- data.table( + dt <- data.table::data.table( x = c("A.B", "A", "B", "B.A"), y = 1:4 ) - expect_equal( - capture.output(dt_separate(dt, x, c("c1", "c2"))[]), - c( - " y c1 c2", - "1: 1 A B", - "2: 2 A ", - "3: 3 B ", - "4: 4 B A" - ) + dt2 <- dt_separate(dt, x, c("c1", "c2")) + dt3 <- data.table::data.table( + y = 1:4, + c1 = c("A", "A", "B", "B"), + c2 = c("B", NA_character_, NA_character_, "A") ) + expect_equal(dt2, dt3) + # can keep the original column with `remove = FALSE` - expect_equal( - capture.output(dt_separate(dt, x, c("c1", "c2"), remove = FALSE)[]), - c( - " x y c1 c2", - "1: A.B 1 A B", - "2: A 2 A ", - "3: B 3 B ", - "4: B.A 4 B A" - ) + dt4 <- dt_separate(dt, x, c("c1", "c2"), remove = FALSE) + dt5 <- data.table::data.table( + x = c("A.B", "A", "B", "B.A"), + y = 1:4, + c1 = c("A", "A", "B", "B"), + c2 = c("B", NA_character_, NA_character_, "A") ) + expect_equal(dt4, dt5) + # need to assign when `immutable = TRUE` - expect_equal( - capture.output(dt_separate(dt, x, c("c1", "c2"), immutable = TRUE)), - c( - " y c1 c2", - "1: 1 A B", - "2: 2 A ", - "3: 3 B ", - "4: 4 B A" - ) - ) -}) + dt6 <- dt_separate(dt, x, c("c1", "c2"), immutable = TRUE) + expect_equal(dt6, dt3) +}) +# now the default so set options to old to check test_that("dt_print_options works", { - dt <- data.table(x = 1) + options("datatable.print.class" = FALSE) + dt <- data.table::data.table(x = 1) dt_print_options() expect_equal( @@ -197,7 +188,7 @@ test_that("dt_print_options works", { test_that("dt_fill works", { - dt <- data.table( + dt <- data.table::data.table( x = c(1,2,3,4,NA), y = c(NA, 1,2,3,4), grp = c(1,2,1,2,1)