Skip to content

Commit

Permalink
Remove all-NA variable_level column from regression ARD output
Browse files Browse the repository at this point in the history
  • Loading branch information
edelarua committed Apr 22, 2024
1 parent 21f53c3 commit cf1e572
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions R/ard_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ ard_regression.default <- function(x, tidy_fun = broom.helpers::tidy_with_broom_
values_to = "stat"
) |>
dplyr::filter(map_lgl(.data$stat, Negate(is.na))) |>
dplyr::select(-(cards::all_ard_variables("levels") & dplyr::where(\(x) all(is.na(x))))) |>
dplyr::mutate(
fmt_fn =
lapply(
Expand Down
3 changes: 2 additions & 1 deletion R/ard_regression_basic.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ ard_regression_basic <- function(x, tidy_fun = broom.helpers::tidy_with_broom_or
utils::modifyList(val = rlang::dots_list(...))

rlang::inject(ard_regression(x = x, tidy_fun = tidy_fun, !!!args)) |>
dplyr::filter(!.data$stat_name %in% stats_to_remove)
dplyr::filter(!.data$stat_name %in% stats_to_remove) |>
dplyr::select(-(cards::all_ard_variables("levels") & dplyr::where(\(x) all(is.na(x)))))
}
4 changes: 4 additions & 0 deletions tests/testthat/test-ard_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ test_that("ard_regression() works", {
"Treatment Arm"
)
})

test_that("ard_regression() does not produce `variable_level` column where not applicable", {
expect_true(!"variable_level" %in% names(lm(mpg ~ hp, mtcars) |> ard_regression()))
})
4 changes: 4 additions & 0 deletions tests/testthat/test-ard_regression_basic.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ test_that("ard_regression_basic() works", {

expect_snapshot(as.data.frame(ard) |> dplyr::select(-fmt_fn))
})

test_that("ard_regression_basic() does not produce `variable_level` column where not applicable", {
expect_true(!"variable_level" %in% names(lm(mpg ~ hp, mtcars) |> ard_regression_basic()))
})

0 comments on commit cf1e572

Please sign in to comment.