From cf1e5729fb2e8a994f823fb0a67a0e1ce9fe44fa Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Mon, 22 Apr 2024 18:16:13 -0400 Subject: [PATCH] Remove all-NA `variable_level` column from regression ARD output --- R/ard_regression.R | 1 + R/ard_regression_basic.R | 3 ++- tests/testthat/test-ard_regression.R | 4 ++++ tests/testthat/test-ard_regression_basic.R | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/R/ard_regression.R b/R/ard_regression.R index a7b0561cb..f07fabc7d 100644 --- a/R/ard_regression.R +++ b/R/ard_regression.R @@ -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( diff --git a/R/ard_regression_basic.R b/R/ard_regression_basic.R index e923245fb..c9a5b3ebe 100644 --- a/R/ard_regression_basic.R +++ b/R/ard_regression_basic.R @@ -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))))) } diff --git a/tests/testthat/test-ard_regression.R b/tests/testthat/test-ard_regression.R index 6fec0806e..7b834e764 100644 --- a/tests/testthat/test-ard_regression.R +++ b/tests/testthat/test-ard_regression.R @@ -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())) +}) diff --git a/tests/testthat/test-ard_regression_basic.R b/tests/testthat/test-ard_regression_basic.R index 93932b563..487426348 100644 --- a/tests/testthat/test-ard_regression_basic.R +++ b/tests/testthat/test-ard_regression_basic.R @@ -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())) +})