Skip to content

Commit

Permalink
retain label for data frames (#2019)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg authored Oct 3, 2024
1 parent c0602c5 commit 928e43a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/tbl_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ tbl_summary <- function(data,

obs_to_drop <- is.na(data[[by]])
cli::cli_inform("{.val {sum(obs_to_drop)}} missing rows in the {.val {by}} column have been removed.")
data[!obs_to_drop, ]
dplyr::filter(data, !obs_to_drop)
}

.check_stats_available <- function(cards, statistic) {
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-tbl_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -653,3 +653,16 @@ test_that("tbl_summary() edge case of warning condition printing", {
as_kable()
)
})

# addressing issue #2017
test_that("tbl_summary() data frame column labels are not dropped", {
expect_equal(
trial |>
as.data.frame() |>
tbl_summary(by = response, include = age) |>
as.data.frame(col_label = FALSE) |>
dplyr::pull(label) |>
dplyr::first(),
"Age"
)
})

0 comments on commit 928e43a

Please sign in to comment.