Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 15, 2024
1 parent 3f688ad commit b4020e6
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
5 changes: 3 additions & 2 deletions R/display.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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, ...
)
}
}
Expand Down
6 changes: 4 additions & 2 deletions R/print_md.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions R/utils_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
# here we either have "<br>" or " " as line breaks, followed by empty "()"
i <- gsub("<br>()", "", i, fixed = TRUE)
i <- gsub(" ()", "", i, fixed = TRUE)
i <- gsub("<br>(, )", "", i, fixed = TRUE)
i <- gsub(" (, )", "", i, fixed = TRUE)
i[i == "()"] <- ""
i[i == "(, )"] <- ""
Expand Down
28 changes: 28 additions & 0 deletions tests/testthat/_snaps/include_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
+--------------+----------------------+----------------------+

7 changes: 6 additions & 1 deletion tests/testthat/test-include_reference.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) |>
Expand Down

0 comments on commit b4020e6

Please sign in to comment.