Skip to content
Open
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Bug Fixes
* Fixed bug in `tabulate_rsp_subgroups()` and `tabulate_survival_subgroups()` preventing risk difference column format specified via `control_riskdiff()` from being applied.
* Fixed bug in `a_summary()` causing an error when all values of a factor input variable were `NA`.

# tern 0.9.9

Expand Down
2 changes: 1 addition & 1 deletion R/analyze_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ s_summary.factor <- function(x, denom = c("n", "N_col", "N_row"), ...) {

y$n_blq <- list("n_blq" = c("n_blq" = sum(grepl("BLQ|LTR|<[1-9]|<PCLLOQ", x))))


if (isTRUE(compare_with_ref_group)) {
.ref_group <- as_factor_keep_attributes(args_list[[".ref_group"]], verbose = verbose)
.in_ref_col <- args_list[[".in_ref_col"]]
Expand Down Expand Up @@ -614,6 +613,7 @@ a_summary <- function(x,

is_char <- is.character(x) || is.factor(x)
if (is_char) {
x_stats <- x_stats[sapply(x_stats, \(x) length(x) > 0 || is.numeric(x))] # only return non-empty stats
levels_per_stats <- lapply(x_stats, names)
} else {
levels_per_stats <- names(x_stats) %>%
Expand Down
45 changes: 45 additions & 0 deletions tests/testthat/test-analyze_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -683,3 +683,48 @@ testthat::test_that("analyze_vars warnings for geom_verbose work", {
# Do we expect output to be NA?
expect_true(all(is.na(cell_values(result2)[[1]])))
})

testthat::test_that("analyze_vars works with all-NA factor input", {
data_mtcars <- mtcars
data_mtcars$hp2 <- as.factor("<Missing>")

res <- basic_table() %>%
analyze_vars(
vars = c("hp2"),
.stats = c("n", "count_fraction", "count"),
na_rm = TRUE
) %>%
build_table(data_mtcars)

expect_identical(
strsplit(toString(matrix_form(res), hsep = "-"), "\n")[[1]],
c(
" all obs",
"-----------",
"n 0 "
)
)
})

testthat::test_that("analyze_vars works with all-NA character input", {
data_mtcars <- mtcars
data_mtcars$hp2 <- "<Missing>"

res <- basic_table() %>%
analyze_vars(
vars = c("hp2"),
.stats = c("n", "count_fraction", "count"),
na_rm = TRUE,
verbose = FALSE
) %>%
build_table(data_mtcars)

expect_identical(
strsplit(toString(matrix_form(res), hsep = "-"), "\n")[[1]],
c(
" all obs",
"-----------",
"n 0 "
)
)
})
Loading