File: test-data.table.R

package info (click to toggle)
r-cran-skimr 2.1.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,188 kB
  • sloc: sh: 13; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 1,764 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

test_that("skim of a simple data.table produces no warnings", {
  skip_if_not_installed("data.table")
  withr::local_options(list(width = 91))
  DT_letters <- data.table::data.table(abc = letters)
  expect_warning(skim(DT_letters), NA)
})

test_that("skim of a simple data.table produces no warnings even with dtplyr", {
  skip_if_not_installed("data.table")
  skip_if_not_installed("dtplyr")
  withr::local_options(list(width = 91))
  DT_letters <- data.table::data.table(abc = letters)
  expect_warning(skim(DT_letters), NA)
})

test_that("skim of a simple data.table produces output as expected", {
  skip_if_not_installed("data.table")
  DT_letters <- data.table::data.table(abc = letters)

  skimmed_DT_letters <- skim(DT_letters)
  withr::local_options(list(cli.unicode = FALSE, width = 91))
  expect_print_matches_file(
    skimmed_DT_letters,
    "data.table/summary_DT_letters.txt"
  )
})


test_that("skim of data.table produces output as expected", {
  skip_if_not_installed("data.table")
  set.seed(1L)

  DT_factors <- data.table::data.table(
    abc = letters,
    grps = factor(sample(c("AA", "BB"), 26, TRUE)),
    values = rnorm(26)
  )

  withr::local_options(list(cli.unicode = FALSE, width = 91))

  expect_print_matches_file(
    skim(DT_factors),
    "data.table/summary_DT_factors_no_key.txt"
  )

  data.table::setkeyv(DT_factors, c("abc", "grps"))
  expect_print_matches_file(
    skim(DT_factors),
    "data.table/summary_DT_factors.txt"
  )

  DF_factors <- as.data.frame(DT_factors)
  expect_print_matches_file(
    skim(DF_factors),
    "data.table/summary_DF_factors.txt"
  )

  tibble_factors <- tibble::as_tibble(DT_factors)
  expect_print_matches_file(
    skim(tibble_factors),
    "data.table/summary_tibble_factors.txt"
  )
})