File: test-dplyr.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 (48 lines) | stat: -rw-r--r-- 1,793 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
skimmed_iris <- skim(iris)

test_that("dplyr::filter works as expected", {
  skip_if_not(l10n_info()$`UTF-8`)
  withr::local_options(list(cli.unicode = FALSE))
  input <- dplyr::filter(skimmed_iris, skim_type == "numeric")
  expect_print_matches_file(input, "dplyr/filter-skim.txt")
  no_rows <- dplyr::filter(skimmed_iris, skim_type == "no_type")
  expect_print_matches_file(no_rows, "dplyr/filter-no-skim.txt")
})

test_that("dplyr::select works as expected", {
  skip_if_not(l10n_info()$`UTF-8`)
  withr::local_options(list(cli.unicode = FALSE))
  with_type <- dplyr::select(skimmed_iris, skim_type, skim_variable)
  expect_print_matches_file(with_type, "dplyr/select-skim.txt")

  without_type <- dplyr::select(skimmed_iris, numeric.mean)
  withr::local_options(list(cli.unicode = FALSE))
  expect_print_matches_file(without_type, "dplyr/select-no-skim.txt")
})

test_that("dplyr::mutate works as expected", {
  skip_if_not(l10n_info()$`UTF-8`)
  withr::local_options(list(cli.unicode = FALSE))
  input <- dplyr::mutate(skimmed_iris, mean2 = numeric.mean^2)
  expect_print_matches_file(input, "dplyr/mutate-skim.txt")

  no_variable <- dplyr::mutate(skimmed_iris, skim_variable = NULL)
  identical(
    capture.output(print(no_variable)),
    capture.output(print(tibble::as_tibble(no_variable)))
  )
})

test_that("dplyr::slice works as expected", {
  skip_if_not(l10n_info()$`UTF-8`)
  withr::local_options(list(cli.unicode = FALSE))
  input <- dplyr::slice(skimmed_iris, 1:3)
  expect_print_matches_file(input, "dplyr/slice.txt")
})

test_that("dplyr::arrange works as expected", {
  skip_if_not(l10n_info()$`UTF-8`)
  withr::local_options(list(cli.unicode = FALSE))
  input <- dplyr::arrange(skimmed_iris, desc(numeric.mean))
  expect_print_matches_file(input, "dplyr/arrange.txt")
})