Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Feb 13, 2024
1 parent 0d69566 commit f34e78c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/data_tabulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @param by Optional vector or factor. If supplied, a crosstable is created.
#' If `x` is a data frame, `by` can also be a character string indicating the
#' name of a variable in `x`.
#' @param drop_levels Logical, if `TRUE`, factor levels that do not occur in
#' @param drop_levels Logical, if `FALSE`, factor levels that do not occur in
#' the data are included in the table (with frequency of zero), else unused
#' factor levels are dropped from the frequency table.
#' @param name Optional character string, which includes the name that is used
Expand Down
2 changes: 1 addition & 1 deletion man/data_tabulate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/testthat/test-data_tabulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ test_that("data_tabulate print, collapse groups, drop levels", {
)
})

test_that("data_tabulate drop levels", {
x <- factor(rep(letters[1:3], 3), levels = letters[1:5])
out1 <- data_tabulate(x, drop_levels = FALSE)
out2 <- data_tabulate(x, drop_levels = TRUE)
expect_identical(out1$N, c(3L, 3L, 3L, 0L, 0L, 0L))
expect_identical(as.character(out1$Value), c("a", "b", "c", "d", "e", NA))
expect_identical(out2$N, c(3L, 3L, 3L, 0L))
expect_identical(as.character(out2$Value), c("a", "b", "c", NA))
})


# select helpers ------------------------------
test_that("data_tabulate regex", {
Expand All @@ -254,6 +264,8 @@ test_that("data_tabulate regex", {
})


# missing values ------------------------------

test_that("data_tabulate exclude/include missing values", {
data(efc, package = "datawizard")
set.seed(123)
Expand Down

0 comments on commit f34e78c

Please sign in to comment.