File: test-skim_print.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 (127 lines) | stat: -rw-r--r-- 4,284 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
test_that("Skim prints a header for the entire output and each type", {
  withr::local_options(list(cli.unicode = FALSE))
  skip_if_not(l10n_info()$`UTF-8`)
  input <- skim(iris)
  expect_print_matches_file(input, "print/default.txt")

  input$numeric.hist <- NULL
  expect_print_matches_file(input, "print/no-hist.txt",
    skip_on_windows = FALSE
  )
})

test_that("Skim prints a special header for grouped data frames", {
  skip_if_not(l10n_info()$`UTF-8`)
  withr::local_options(list(cli.unicode = FALSE))
  input <- skim(dplyr::group_by(iris, Species))
  expect_print_matches_file(input, "print/groups.txt")
})

test_that("Skim lists print as expected", {
  skip_if_not(l10n_info()$`UTF-8`)
  withr::local_options(list(cli.unicode = FALSE))
  skimmed <- skim(iris)
  input <- partition(skimmed)
  expect_print_matches_file(input, "print/list.txt")
})

test_that("knit_print produces expected results", {
  skip_if_not(l10n_info()$`UTF-8`)
  withr::local_options(list(cli.unicode = FALSE))
  skimmed <- skim(iris)
  input <- knit_print(skimmed)
  expect_s3_class(input, "knit_asis")
  expect_length(input, 1)
  expect_matches_file(input, "print/knit_print.txt")
})

test_that("knit_print works with skim summaries", {
  withr::local_options(list(cli.unicode = FALSE))
  skimmed <- skim(iris)
  summarized <- summary(skimmed)
  input <- knitr::knit_print(summarized)
  expect_matches_file(input, "print/knit_print-summary.txt")
})

test_that("knit_print appropriately falls back to tibble printing", {
  withr::local_options(list(cli.unicode = FALSE))
  skimmed <- skim(iris)
  reduced <- dplyr::select(skimmed, skim_variable, numeric.mean)
  printed <- testthat::capture_output(input <- knitr::knit_print(reduced))
  expect_matches_file(printed, "print/knit_print-fallback.txt")
  expect_s3_class(input, "data.frame")
})

test_that("Summaries can be suppressed within knitr", {
  skip_if_not(l10n_info()$`UTF-8`)
  withr::local_options(list(cli.unicode = FALSE))
  skimmed <- skim(iris)
  options <- list(skimr_include_summary = FALSE)
  input <- knitr::knit_print(skimmed, options = options)
  expect_matches_file(input, "print/knit_print-suppressed.txt")
})

test_that("Skim lists have a separate knit_print method", {
  skip_if_not(l10n_info()$`UTF-8`)
  withr::local_options(list(cli.unicode = FALSE))
  skimmed <- skim(iris)
  skim_list <- partition(skimmed)
  input <- knit_print(skim_list)
  expect_matches_file(input, "print/knit_print-skim_list.txt")
})

test_that("You can yank a type from a skim_df and call knit_print", {
  withr::local_options(list(cli.unicode = FALSE))
  skimmed <- skim(iris)
  skim_one <- yank(skimmed, "factor")
  input <- knit_print(skim_one)
  expect_matches_file(input, "print/knit_print-yank.txt")
})

test_that("make_utf8 produces the correct result ", {
  withr::local_options(list(cli.unicode = FALSE))
  input <- make_utf8(c("<U+2585><U+2587>"))
  correct <- "▅"
  expect_identical(input, correct)
})

test_that("Skim falls back to tibble::print.tbl() appropriately", {
  withr::local_options(list(cli.unicode = FALSE))
  input <- skim(iris)
  mean_only <- dplyr::select(input, numeric.mean)
  expect_print_matches_file(mean_only, "print/fallback.txt")
})

test_that("Print focused objects appropriately", {
  withr::local_options(list(cli.unicode = FALSE))
  skip_if_not(l10n_info()$`UTF-8`)
  skimmed <- skim(iris)
  input <- focus(skimmed, n_missing)
  expect_print_matches_file(input, "print/focus.txt")
})

test_that("Support for smaller consoles can be set with the width option", {
  withr::local_options(list(cli.unicode = FALSE))
  skip_if_not(l10n_info()$`UTF-8`)
  skimmed <- skim(iris)
  expect_print_matches_file(skimmed, "print/smaller.txt", width = 50)
})

test_that("Table header width can be controlled by an option", {
  withr::local_options(list(cli.unicode = FALSE))
  skip_if_not(l10n_info()$`UTF-8`)
  skimmed <- skim(iris)
  expect_print_matches_file(
    skimmed,
    "print/narrow-header.txt",
    skimr_table_header_width = 50
  )
})

test_that("skimr creates appropriate output for Jupyter", {
  withr::local_options(list(cli.unicode = FALSE))
  skip_if_not(l10n_info()$`UTF-8`)
  skimmed <- skim(iris)
  input <- testthat::capture_output(repr_text(skimmed))
  expect_matches_file(input, "print/repr.txt")
})