Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@
Package: report
Type: Package
Title: Automated Reporting of Results and Statistical Models
Version: 0.6.4.19
Version: 0.6.4.20
Authors@R:
c(person(given = "Dominique",
family = "Makowski",
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Bug fixes

* Fixed an issue in `report()` where the reference level for logical predictors was incorrectly displayed as `[?]` instead of `FALSE` for the intercept (@M-Colley, #598).

* `report()` preserves data-frame reports and variable names when only one supported column remains.

* `report()` handles `var.test()` results and reports the F statistic with both degrees of freedom, the p-value, and the variance ratio with its confidence interval (#238).

* Fixed `report()` text for `stanreg` and `brmsfit` models with predictors out of alphabetical order, which gave parameters the wrong Rhat and ESS. Earlier reports of such models had wrong values (@jmgirard, #343).
Expand Down
10 changes: 8 additions & 2 deletions R/report.data.frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ report.data.frame <- function(
# remove list columns
if (.has_groups(x) && !inherits(x, "tbl_df")) {
x <- .groups_set(
x[, vapply(x, Negate(inherits), what = "list", FUN.VALUE = TRUE)],
x[,
vapply(x, Negate(inherits), what = "list", FUN.VALUE = TRUE),
drop = FALSE
],
groups = .group_vars(x),
drop = .groups_drop(x)
)
} else {
x <- x[, vapply(x, Negate(inherits), what = "list", FUN.VALUE = TRUE)]
x <- x[,
vapply(x, Negate(inherits), what = "list", FUN.VALUE = TRUE),
drop = FALSE
]
}

result_table <-
Expand Down
39 changes: 32 additions & 7 deletions tests/testthat/test-report.data.frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ test_that("report.numeric", {
test_that("report.character", {
x <- c("A", "B", "C", "A", "B", "B", "D", "E", "B", "D", "A")
r <- report(x)
expect_equal(nrow(as.data.frame(r)), 1, tolerance = 0)
expect_length(as.data.frame(r)$n_Obs, 1)
expect_null(as.data.frame(r)$Median)

r <- report(x, levels_percentage = FALSE, missing_percentage = TRUE)
expect_equal(nrow(as.data.frame(r)), 1, tolerance = 0)
expect_length(as.data.frame(r)$n_Obs, 1)
expect_equal(as.data.frame(r)$percentage_Missing[1], 0, tolerance = 0)
})

test_that("report.factor", {
r <- report(factor(rep(c("A", "B", "C"), 10)))
expect_equal(nrow(as.data.frame(r)), 3, tolerance = 0)
expect_length(as.data.frame(r)$n_Obs, 3)
expect_null(as.data.frame(r)$Median)
expect_snapshot(variant = "windows", r)

r <- report(factor(rep(c("A", "B", "C", NA), 10)), levels_percentage = FALSE)
expect_equal(nrow(as.data.frame(r)), 4, tolerance = 0)
expect_length(as.data.frame(r)$n_Obs, 4)
})

test_that("report.Date", {
Expand All @@ -62,7 +62,7 @@ test_that("report.data.frame", {
skip_if_not_installed("dplyr")

r <- report(iris)
expect_equal(nrow(as.data.frame(r)), 7, tolerance = 0)
expect_length(as.data.frame(r)$n_Obs, 7)
expect_equal(mean(as.data.frame(r)$Median, na.rm = TRUE), 3.6125)

r <- report(
Expand All @@ -73,11 +73,11 @@ test_that("report.data.frame", {
range = FALSE,
dispersion = FALSE
)
expect_equal(nrow(as.data.frame(r)), 7, tolerance = 0)
expect_length(as.data.frame(r)$n_Obs, 7)
expect_equal(mean(as.data.frame(r)$n_Obs), 107, tolerance = 0.01)

r <- report(dplyr::group_by(iris, Species))
expect_equal(nrow(as.data.frame(r)), 12, tolerance = 0)
expect_length(as.data.frame(r)$n_Obs, 12)
expect_equal(mean(as.data.frame(r)$n_Obs), 50, tolerance = 0)

expect_snapshot(variant = "windows", r)
Expand All @@ -100,3 +100,28 @@ test_that("report.data.frame - with list columns", {
set.seed(123)
expect_snapshot(variant = "windows", report(dplyr::starwars))
})

test_that("report.data.frame preserves a single supported column", {
with_list <- data.frame(score = 1:5)
with_list$details <- as.list(letters[1:5])
datasets <- list(
data.frame(score = 1:5),
data.frame(group = factor(c("A", "B", "A", "B", "A"))),
with_list
)

for (data in datasets) {
result <- report(data)
table <- as.report_table(result)
text <- paste(as.character(result), collapse = "\n")

expect_match(
text,
"The data contains 5 observations of the following 1 variables:",
fixed = TRUE
)
expect_match(text, paste0(" - ", names(data)[1], ":"), fixed = TRUE)
expect_identical(unique(table$Variable), names(data)[1])
expect_identical(unique(summary(table)$Variable), names(data)[1])
}
})
Loading