Skip to content

Commit

Permalink
one more test
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Feb 13, 2024
1 parent 42fcaf1 commit c173c1c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/testthat/test-data_tabulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,21 @@ test_that("data_tabulate, cross tables, markdown", {
expect_snapshot(print_md(data_tabulate(efc$c172code, by = efc$e16sex, proportions = "full", weights = efc$weights)))
expect_snapshot(print_md(data_tabulate(efc$c172code, by = efc$e16sex, proportions = "full", include_na = FALSE, weights = efc$weights))) # nolint
})

# validate against table -------------------------

test_that("data_tabulate, validate against table", {
data(mtcars)
# frequency table
out1 <- as.data.frame(table(mtcars$cyl))
out2 <- data_tabulate(mtcars$cyl, include_na = FALSE)
expect_identical(out1$Freq, out2$N)
# crosstable
out1 <- data_arrange(as.data.frame(table(mtcars$cyl, mtcars$gear)), c("Var1", "Var2"))
out2 <- data_rename(data_to_long(
as.data.frame(data_tabulate(mtcars$cyl, by = mtcars$gear, include_na = FALSE)), 2:4,
names_to = "Var2", values_to = "Freq"
), "mtcars$cyl", "Var1")
out1[[2]] <- as.character(out1[[2]])
expect_equal(out1, out2, ignore_attr = TRUE)
})

0 comments on commit c173c1c

Please sign in to comment.