From b4020e6efa43e72e36f093beab46067fced916cf Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 15 Mar 2024 08:53:31 +0100 Subject: [PATCH] update test --- R/display.R | 5 ++-- R/print_md.R | 6 +++-- R/utils_format.R | 1 + tests/testthat/_snaps/include_reference.md | 28 ++++++++++++++++++++++ tests/testthat/test-include_reference.R | 7 +++++- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/R/display.R b/R/display.R index ba45e6a66..334854250 100644 --- a/R/display.R +++ b/R/display.R @@ -115,7 +115,8 @@ display.parameters_model <- function(object, footer_digits = footer_digits, align = align, ci_brackets = ci_brackets, show_sigma = show_sigma, show_formula = show_formula, zap_small = zap_small, font_size = font_size, line_padding = line_padding, - column_labels = column_labels, verbose = verbose, ... + column_labels = column_labels, include_reference = include_reference, + verbose = verbose, ... ) } else { print_md( @@ -124,7 +125,7 @@ display.parameters_model <- function(object, footer = footer, ci_digits = ci_digits, p_digits = p_digits, footer_digits = footer_digits, ci_brackets = ci_brackets, show_sigma = show_sigma, show_formula = show_formula, zap_small = zap_small, - verbose = verbose, ... + include_reference = include_reference, verbose = verbose, ... ) } } diff --git a/R/print_md.R b/R/print_md.R index 98a7adbec..5a4990f54 100644 --- a/R/print_md.R +++ b/R/print_md.R @@ -443,8 +443,10 @@ print_md.parameters_distribution <- function(x, digits = 2, ci_brackets = c("(", formatted_table[is.na(formatted_table)] <- "" # create base table out <- tinytable::tt(formatted_table, notes = footer, caption = caption) - # insert sub header rows and column spans - out <- tinytable::group_tt(out, i = row_groups, j = col_groups) + # insert sub header rows and column spans, if we have them + if (!(is.null(row_groups) && is.null(col_groups))) { + out <- tinytable::group_tt(out, i = row_groups, j = col_groups) + } out@output <- outformat out } diff --git a/R/utils_format.R b/R/utils_format.R index 7f65eef26..00dc350d5 100644 --- a/R/utils_format.R +++ b/R/utils_format.R @@ -53,6 +53,7 @@ # here we either have "
" or " " as line breaks, followed by empty "()" i <- gsub("
()", "", i, fixed = TRUE) i <- gsub(" ()", "", i, fixed = TRUE) + i <- gsub("
(, )", "", i, fixed = TRUE) i <- gsub(" (, )", "", i, fixed = TRUE) i[i == "()"] <- "" i[i == "(, )"] <- "" diff --git a/tests/testthat/_snaps/include_reference.md b/tests/testthat/_snaps/include_reference.md index ff6c1d4b8..a4f1fbc61 100644 --- a/tests/testthat/_snaps/include_reference.md +++ b/tests/testthat/_snaps/include_reference.md @@ -36,3 +36,31 @@ Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed using a Wald t-distribution approximation. +--- + + Code + print_md(out, engine = "tt") + Output + + +--------------+----------------------+----------------------+ + | Parameter | m1 | m2 | + +==============+======================+======================+ + | (Intercept) | 27.48 (23.43, 31.53) | 27.48 (23.43, 31.53) | + +--------------+----------------------+----------------------+ + | gear (3) | 0.00 | 0.00 | + +--------------+----------------------+----------------------+ + | gear (4) | 0.08 (-3.68, 3.83) | 0.08 (-3.68, 3.83) | + +--------------+----------------------+----------------------+ + | gear (5) | 2.39 (-2.50, 7.29) | 2.39 (-2.50, 7.29) | + +--------------+----------------------+----------------------+ + | am (0) | 0.00 | 0.00 | + +--------------+----------------------+----------------------+ + | am (1) | 4.14 (0.42, 7.85) | 4.14 (0.42, 7.85) | + +--------------+----------------------+----------------------+ + | hp | -0.06 (-0.09, -0.04) | -0.06 (-0.09, -0.04) | + +--------------+----------------------+----------------------+ + | | | | + +--------------+----------------------+----------------------+ + | Observations | 32 | 32 | + +--------------+----------------------+----------------------+ + diff --git a/tests/testthat/test-include_reference.R b/tests/testthat/test-include_reference.R index 00456c007..2d9d7e6c7 100644 --- a/tests/testthat/test-include_reference.R +++ b/tests/testthat/test-include_reference.R @@ -19,7 +19,12 @@ test_that("include_reference, on-the-fly factors", { expect_equal(attributes(out1)$pretty_names, attributes(out2)$pretty_names, ignore_attr = TRUE) expect_equal(out1$Coefficient, out2$Coefficient, tolerance = 1e-4) - skip_if(getRversion() < "4.3.0") + skip_if_not_installed("tinytable") + out <- compare_parameters(m1, m2, include_reference = TRUE) + expect_snapshot(print_md(out, engine = "tt")) + + + skip_if(getRversion() < "4.3.2") skip_if_not_installed("datawizard") out3 <- mtcars |> datawizard::data_modify(gear = factor(gear), am = as.factor(am)) |>