33# '
44# ' @description Prints tables (i.e. data frame) in different output formats.
55# ' `print_md()` is an alias for `display(format = "markdown")`, `print_html()`
6- # ' is an alias for `display(format = "html")`. `print_table()` is for specific
7- # ' use cases only, and currently only works for `compare_parameters()` objects.
6+ # ' is an alias for `display(format = "html")`, and `print_html(engine = "tt")`
7+ # ' is an alias for `display(format = "tt")`. The latter is a `tinytable` object,
8+ # ' which is either printed as markdown or HTML table, depending on the environment.
89# '
9- # ' @param x An object returned by [`model_parameters()`].
10- # ' @param object An object returned by [`model_parameters()`],[`simulate_parameters()`],
11- # ' [`equivalence_test()`] or [` principal_components()`].
10+ # ' @param object An object returned by one of the package's function, for example
11+ # ' [`model_parameters()`], [`simulate_parameters()`], [`equivalence_test()`] or
12+ # ' [`principal_components()`].
1213# ' @param format String, indicating the output format. Can be `"markdown"`
13- # ' or `"html"`.
14+ # ' `"html"`, or `"tt"`. `format = "tt"` creates a `tinytable` object, which is
15+ # ' either printed as markdown or HTML table, depending on the environment. See
16+ # ' [`insight::export_table()`] for details.
1417# ' @param align Only applies to HTML tables. May be one of `"left"`,
1518# ' `"right"` or `"center"`.
1619# ' @param digits,ci_digits,p_digits Number of digits for rounding or
2730# ' @param line_padding For HTML tables, the distance (in pixel) between lines.
2831# ' @param column_labels Labels of columns for HTML tables. If `NULL`, automatic
2932# ' column names are generated. See 'Examples'.
30- # ' @param theme String, indicating the table theme. Can be one of `"default"`,
31- # ' `"grid"`, `"striped"`, `"bootstrap"` or `"darklines"`.
3233# ' @inheritParams print.parameters_model
3334# ' @inheritParams insight::format_table
3435# ' @inheritParams insight::export_table
3536# ' @inheritParams compare_parameters
3637# '
3738# ' @return If `format = "markdown"`, the return value will be a character
3839# ' vector in markdown-table format. If `format = "html"`, an object of
39- # ' class `gt_tbl`. For `print_table()`, an object of class `tinytable` is
40- # ' returned.
40+ # ' class `gt_tbl`. If `format = "tt"`, an object of class `tinytable`.
4141# '
4242# ' @details `display()` is useful when the table-output from functions,
4343# ' which is usually printed as formatted text-table to console, should
4646# ' [vignette](https://easystats.github.io/parameters/articles/model_parameters_formatting.html)
4747# ' for examples.
4848# '
49- # ' `print_table()` is a special function for `compare_parameters()` objects,
50- # ' which prints the output as a formatted HTML table. It is still somewhat
51- # ' experimental, thus, only a fixed layout-style is available at the moment
52- # ' (columns for estimates, confidence intervals and p-values). However, it
53- # ' is possible to include other model components, like zero-inflation, or random
54- # ' effects in the table. See 'Examples'. An alternative is to set `engine = "tt"`
55- # ' in `print_html()` to use the _tinytable_ package for creating HTML tables.
56- # '
5749# ' @seealso [print.parameters_model()] and [print.compare_parameters()]
5850# '
5951# ' @examplesIf require("gt", quietly = TRUE)
8173# ' column_labels = c("Est. (95% CI)")
8274# ' )
8375# ' }
76+ # '
77+ # ' @examplesIf all(insight::check_if_installed(c("glmmTMB", "lme4", "tinytable"), quietly = TRUE))
78+ # ' \donttest{
79+ # ' data(iris)
80+ # ' data(Salamanders, package = "glmmTMB")
81+ # ' m1 <- lm(Sepal.Length ~ Species * Petal.Length, data = iris)
82+ # ' m2 <- lme4::lmer(
83+ # ' Sepal.Length ~ Petal.Length + Petal.Width + (1 | Species),
84+ # ' data = iris
85+ # ' )
86+ # ' m3 <- glmmTMB::glmmTMB(
87+ # ' count ~ spp + mined + (1 | site),
88+ # ' ziformula = ~mined,
89+ # ' family = poisson(),
90+ # ' data = Salamanders
91+ # ' )
92+ # ' out <- compare_parameters(m1, m2, m3, effects = "all", component = "all")
93+ # '
94+ # ' display(out, format = "tt")
95+ # '
96+ # ' display(out, select = "{estimate}|{ci}", format = "tt")
97+ # ' }
8498# ' @export
8599display.parameters_model <- function (object ,
86100 format = " markdown" ,
@@ -123,7 +137,8 @@ display.parameters_model <- function(object,
123137 column_labels = column_labels ,
124138 align = align ,
125139 font_size = font_size ,
126- line_padding = line_padding
140+ line_padding = line_padding ,
141+ engine = ifelse(format == " tt" , " tt" , " gt" )
127142 )
128143 )
129144 do.call(print_html , c(fun_args , list (... )))
@@ -173,7 +188,8 @@ display.compare_parameters <- function(object,
173188 list (
174189 column_labels = column_labels ,
175190 font_size = font_size ,
176- line_padding = line_padding
191+ line_padding = line_padding ,
192+ engine = ifelse(format == " tt" , " tt" , " gt" )
177193 )
178194 )
179195 do.call(print_html , c(fun_args , list (... )))
@@ -202,7 +218,8 @@ display.parameters_sem <- function(object,
202218 digits = digits ,
203219 ci_digits = ci_digits ,
204220 p_digits = p_digits ,
205- ci_brackets = ci_brackets
221+ ci_brackets = ci_brackets ,
222+ engine = ifelse(format == " tt" , " tt" , " gt" )
206223 )
207224
208225 if (format %in% c(" html" , " tt" )) {
@@ -220,7 +237,7 @@ display.parameters_sem <- function(object,
220237# ' @export
221238display.parameters_efa_summary <- function (object , format = " markdown" , digits = 3 , ... ) {
222239 format <- insight :: validate_argument(format , c(" markdown" , " html" , " md" , " tt" ))
223- fun_args <- list (x = object , digits = digits )
240+ fun_args <- list (x = object , digits = digits , engine = ifelse( format == " tt " , " tt " , " gt " ) )
224241
225242 if (format %in% c(" html" , " tt" )) {
226243 do.call(print_html , c(fun_args , list (... )))
@@ -247,7 +264,8 @@ display.parameters_efa <- function(object, format = "markdown", digits = 2, sort
247264 digits = digits ,
248265 sort = sort ,
249266 threshold = threshold ,
250- labels = labels
267+ labels = labels ,
268+ engine = ifelse(format == " tt" , " tt" , " gt" )
251269 )
252270
253271 if (format %in% c(" html" , " tt" )) {
@@ -272,3 +290,32 @@ display.parameters_omega <- display.parameters_efa
272290display.equivalence_test_lm <- function (object , format = " markdown" , digits = 2 , ... ) {
273291 print_md(x = object , digits = digits , ... )
274292}
293+
294+
295+ # p_function ----------------------------
296+
297+ # ' @export
298+ display.parameters_p_function <- function (object ,
299+ format = " markdown" ,
300+ digits = 2 ,
301+ ci_width = " auto" ,
302+ ci_brackets = TRUE ,
303+ pretty_names = TRUE ,
304+ ... ) {
305+ format <- insight :: validate_argument(format , c(" markdown" , " html" , " md" , " tt" ))
306+
307+ fun_args <- list (
308+ x = object ,
309+ digits = digits ,
310+ ci_width = ci_width ,
311+ ci_brackets = ci_brackets ,
312+ pretty_names = pretty_names ,
313+ engine = ifelse(format == " tt" , " tt" , " gt" )
314+ )
315+
316+ if (format %in% c(" html" , " tt" )) {
317+ do.call(print_html , c(fun_args , list (... )))
318+ } else {
319+ do.call(print_md , c(fun_args , list (... )))
320+ }
321+ }
0 commit comments