Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix snapshot tests #560

Merged
merged 9 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: datawizard
Title: Easy Data Wrangling and Statistical Transformations
Version: 0.13.0.9
Version: 0.13.0.11
Authors@R: c(
person("Indrajeet", "Patil", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0003-1995-6531")),
Expand Down
6 changes: 4 additions & 2 deletions R/data_codebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
#'
#' @note There are methods to `print()` the data frame in a nicer output, as
#' well methods for printing in markdown or HTML format (`print_md()` and
#' `print_html()`).
#' `print_html()`). The `print()` method for text outputs passes arguments in
#' `...` to [`insight::export_table()`].
#'
#' @examples
#' data(iris)
Expand Down Expand Up @@ -369,7 +370,8 @@ print.data_codebook <- function(x, ...) {
title = caption,
empty_line = "-",
cross = "+",
align = .get_codebook_align(x)
align = .get_codebook_align(x),
...
)
)
}
Expand Down
9 changes: 6 additions & 3 deletions R/data_tabulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
#' @note
#' There are `print_html()` and `print_md()` methods available for printing
#' frequency or crosstables in HTML and markdown format, e.g.
#' `print_html(data_tabulate(x))`.
#' `print_html(data_tabulate(x))`. The `print()` method for text outputs passes
#' arguments in `...` to [`insight::export_table()`].
#'
#' @return A data frame, or a list of data frames, with one frequency table
#' as data frame per variable.
Expand Down Expand Up @@ -522,7 +523,8 @@ print.datawizard_table <- function(x, big_mark = NULL, ...) {
cat(insight::export_table(
format(x, big_mark = big_mark, ...),
cross = "+",
missing = "<NA>"
missing = "<NA>",
...
))
invisible(x)
}
Expand Down Expand Up @@ -621,7 +623,8 @@ print.datawizard_tables <- function(x, big_mark = NULL, ...) {
out,
missing = "<NA>",
cross = "+",
empty_line = "-"
empty_line = "-",
...
))
}
}
Expand Down
3 changes: 2 additions & 1 deletion R/data_xtabulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ print.datawizard_crosstab <- function(x, big_mark = NULL, ...) {
cross = "+",
missing = "<NA>",
caption = caption,
empty_line = "-"
empty_line = "-",
...
))
invisible(x)
}
Expand Down
2 changes: 1 addition & 1 deletion R/describe_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ print.parameters_distribution <- function(x, digits = 2, ...) {
ci_brackets = TRUE,
...
)
cat(insight::export_table(formatted_table, format = "text", digits = digits))
cat(insight::export_table(formatted_table, format = "text", digits = digits, ...))
invisible(x)
}

Expand Down
3 changes: 2 additions & 1 deletion man/data_codebook.Rd

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

3 changes: 2 additions & 1 deletion man/data_tabulate.Rd

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

264 changes: 261 additions & 3 deletions tests/testthat/_snaps/data_codebook.md

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions tests/testthat/test-data_codebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

set.seed(123)
d <- data.frame(
x = c(sample(1:15, 100, TRUE), Inf, Inf)

Check warning on line 22 in tests/testthat/test-data_codebook.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-data_codebook.R,line=22,col=11,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(1:n, m, ...).
)
expect_snapshot(data_codebook(d))
expect_snapshot(data_codebook(d, range_at = 100))
Expand All @@ -38,24 +38,32 @@


test_that("data_codebook efc", {
expect_snapshot(data_codebook(efc))
expect_snapshot(print(data_codebook(efc), table_width = Inf))
expect_snapshot(print(data_codebook(efc), table_width = "auto", remove_duplicates = FALSE))
expect_snapshot(print(data_codebook(efc), table_width = "auto", remove_duplicates = TRUE))
})


test_that("data_codebook efc, variable_label_width", {
expect_snapshot(data_codebook(efc, variable_label_width = 30))
out <- data_codebook(efc, variable_label_width = 30)
expect_snapshot(print(out, table_width = Inf))
expect_snapshot(print(out, table_width = "auto", remove_duplicates = FALSE))
expect_snapshot(print(out, table_width = "auto", remove_duplicates = TRUE))
})


test_that("data_codebook efc, value_label_width", {
expect_snapshot(data_codebook(efc, variable_label_width = 30, value_label_width = 15))
out <- data_codebook(efc, variable_label_width = 30, value_label_width = 15)
expect_snapshot(print(out, table_width = Inf))
expect_snapshot(print(out, table_width = "auto", remove_duplicates = FALSE))
expect_snapshot(print(out, table_width = "auto", remove_duplicates = TRUE))
})


test_that("data_codebook truncated data", {
set.seed(123)
d <- data.frame(
a = sample(1:15, 100, TRUE),

Check warning on line 66 in tests/testthat/test-data_codebook.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-data_codebook.R,line=66,col=9,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(1:n, m, ...).
b = sample(letters[1:18], 100, TRUE),
stringsAsFactors = FALSE
)
Expand All @@ -66,7 +74,7 @@
test_that("data_codebook mixed numeric lengths", {
set.seed(123)
d <- data.frame(
a = sample(1:4, 100, TRUE),

Check warning on line 77 in tests/testthat/test-data_codebook.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-data_codebook.R,line=77,col=9,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(1:n, m, ...).
b = sample(5:15, 100, TRUE),
stringsAsFactors = FALSE
)
Expand All @@ -76,7 +84,7 @@
test_that("data_codebook mixed range_at", {
set.seed(123)
d <- data.frame(
a = sample(1:4, 100, TRUE),

Check warning on line 87 in tests/testthat/test-data_codebook.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-data_codebook.R,line=87,col=9,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(1:n, m, ...).
b = sample(5:15, 100, TRUE),
stringsAsFactors = FALSE
)
Expand All @@ -87,7 +95,7 @@
test_that("data_codebook logicals", {
set.seed(123)
d <- data.frame(
a = sample(1:15, 100, TRUE),

Check warning on line 98 in tests/testthat/test-data_codebook.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-data_codebook.R,line=98,col=9,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(1:n, m, ...).
b = sample(letters[1:3], 100, TRUE),
c = sample(c(TRUE, FALSE), 100, TRUE),
stringsAsFactors = FALSE
Expand All @@ -99,14 +107,14 @@
test_that("data_codebook labelled data exceptions", {
set.seed(123)

f1 <- sample(1:5, 100, TRUE)

Check warning on line 110 in tests/testthat/test-data_codebook.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-data_codebook.R,line=110,col=9,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(1:n, m, ...).
f1[f1 == 4] <- NA
attr(f1, "labels") <- setNames(1:5, c("One", "Two", "Three", "Four", "Five"))

f2 <- sample(1:5, 100, TRUE)

Check warning on line 114 in tests/testthat/test-data_codebook.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-data_codebook.R,line=114,col=9,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(1:n, m, ...).
attr(f2, "labels") <- setNames(c(1:3, 5), c("One", "Two", "Three", "Five"))

f3 <- sample(1:5, 100, TRUE)

Check warning on line 117 in tests/testthat/test-data_codebook.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-data_codebook.R,line=117,col=9,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(1:n, m, ...).
attr(f3, "labels") <- setNames(1:5, c("One", "Two", "Three", "Four", "Five"))

d <- data.frame(f1, f2, f3)
Expand Down Expand Up @@ -143,7 +151,7 @@
test_that("data_codebook, big marks", {
set.seed(123)
f1 <- factor(sample(c("c", "b", "a"), 1e6, TRUE))
f2 <- factor(sample(1:3, 1e6, TRUE))

Check warning on line 154 in tests/testthat/test-data_codebook.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-data_codebook.R,line=154,col=16,[sample_int_linter] sample.int(n, m, ...) is preferable to sample(1:n, m, ...).
d <- data.frame(f1, f2)
expect_snapshot(data_codebook(d))
})
Expand Down
Loading