From 7c0bb41d7cb5733cfea0d727e450b87f56da2027 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Mon, 29 Apr 2024 13:03:46 -0700 Subject: [PATCH] adding broom.mixed test --- DESCRIPTION | 1 + tests/testthat/test-ard_regression.R | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3839a677f..7940a3542 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,6 +28,7 @@ Suggests: aod (>= 1.3.3), broom (>= 1.0.5), broom.helpers (>= 1.15.0), + broom.mixed (>= 0.2.9), car (>= 3.0-11), effectsize (>= 0.6.0), emmeans (>= 1.7.3), diff --git a/tests/testthat/test-ard_regression.R b/tests/testthat/test-ard_regression.R index 7b834e764..91610c3d2 100644 --- a/tests/testthat/test-ard_regression.R +++ b/tests/testthat/test-ard_regression.R @@ -1,4 +1,4 @@ -skip_if_not(do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom.helpers", reference_pkg = "cardx"))) +skip_if_not(is_pkg_installed(pkg = "broom.helpers", reference_pkg = "cardx")) test_that("ard_regression() works", { expect_snapshot( @@ -21,6 +21,20 @@ test_that("ard_regression() works", { ) }) +test_that("ard_regression() works specifying custom tidier", { + skip_if_not(is_pkg_installed(pkg = c("lme4", "broom.mixed"), reference_pkg = "cardx")) + expect_snapshot( + lme4::lmer(mpg ~ hp + (1 | cyl), data = mtcars) |> + ard_regression(tidy_fun = broom.mixed::tidy) |> + as.data.frame() |> + dplyr::select(-context, -stat_label, -fmt_fn) |> + dplyr::filter(map_lgl(stat, is.numeric)) |> + dplyr::mutate( + stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x)) + ) + ) +}) + 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())) })