From f6765fa01d44ad81b85702c065fbb2007c7d23e7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 21 Jul 2025 23:40:55 +0200 Subject: [PATCH 1/5] Purely internal need --- R/display.R | 12 +++++----- R/p_function.R | 6 +---- R/print_html.R | 49 ++++++++++++++++---------------------- R/standardize_parameters.R | 10 ++++---- R/utils_pca_efa.R | 7 ++---- 5 files changed, 34 insertions(+), 50 deletions(-) diff --git a/R/display.R b/R/display.R index fbc920028..f978a3e08 100644 --- a/R/display.R +++ b/R/display.R @@ -138,7 +138,7 @@ display.parameters_model <- function(object, align = align, font_size = font_size, line_padding = line_padding, - engine = ifelse(format == "tt", "tt", "gt") + backend = ifelse(format == "tt", "tt", "html") ) ) do.call(print_html, c(fun_args, list(...))) @@ -189,7 +189,7 @@ display.compare_parameters <- function(object, column_labels = column_labels, font_size = font_size, line_padding = line_padding, - engine = ifelse(format == "tt", "tt", "gt") + backend = ifelse(format == "tt", "tt", "html") ) ) do.call(print_html, c(fun_args, list(...))) @@ -219,7 +219,7 @@ display.parameters_sem <- function(object, ci_digits = ci_digits, p_digits = p_digits, ci_brackets = ci_brackets, - engine = ifelse(format == "tt", "tt", "gt") + backend = ifelse(format == "tt", "tt", "html") ) if (format %in% c("html", "tt")) { @@ -237,7 +237,7 @@ display.parameters_sem <- function(object, #' @export display.parameters_efa_summary <- function(object, format = "markdown", digits = 3, ...) { format <- insight::validate_argument(format, c("markdown", "html", "md", "tt")) - fun_args <- list(x = object, digits = digits, engine = ifelse(format == "tt", "tt", "gt")) + fun_args <- list(x = object, digits = digits, backend = ifelse(format == "tt", "tt", "html")) if (format %in% c("html", "tt")) { do.call(print_html, c(fun_args, list(...))) @@ -265,7 +265,7 @@ display.parameters_efa <- function(object, format = "markdown", digits = 2, sort sort = sort, threshold = threshold, labels = labels, - engine = ifelse(format == "tt", "tt", "gt") + backend = ifelse(format == "tt", "tt", "html") ) if (format %in% c("html", "tt")) { @@ -310,7 +310,7 @@ display.parameters_p_function <- function(object, ci_width = ci_width, ci_brackets = ci_brackets, pretty_names = pretty_names, - engine = ifelse(format == "tt", "tt", "gt") + backend = ifelse(format == "tt", "tt", "html") ) if (format %in% c("html", "tt")) { diff --git a/R/p_function.R b/R/p_function.R index 69f5087fb..b8ad8d4fa 100644 --- a/R/p_function.R +++ b/R/p_function.R @@ -443,13 +443,9 @@ print.parameters_p_function <- function(x, ci_brackets = c("(", ")"), pretty_names = TRUE, format = "html", - engine = "gt", ...) { # which engine? - engine <- insight::validate_argument( - getOption("easystats_html_engine", engine), - c("gt", "default", "tt") - ) + engine <- .check_format_backend(...) formatted_table <- format( x, diff --git a/R/print_html.R b/R/print_html.R index 84385ed17..7c348b74d 100644 --- a/R/print_html.R +++ b/R/print_html.R @@ -23,14 +23,10 @@ print_html.parameters_model <- function(x, line_padding = 4, column_labels = NULL, include_reference = FALSE, - engine = "gt", verbose = TRUE, ...) { # which engine? - engine <- insight::validate_argument( - getOption("easystats_html_engine", engine), - c("gt", "default", "tt") - ) + engine <- .check_format_backend(...) # line separator - for tinytable, we have no specific line separator, # because the output format is context-dependent @@ -123,7 +119,7 @@ print_html.parameters_model <- function(x, out <- insight::export_table( formatted_table, - format = ifelse(identical(engine, "tt"), "tt", "html"), + format = engine, caption = table_caption, subtitle = subtitle, footer = footer, @@ -170,7 +166,6 @@ print_html.compare_parameters <- function(x, font_size = "100%", line_padding = 4, column_labels = NULL, - engine = "gt", ...) { # check if user supplied digits attributes if (missing(digits)) { @@ -191,10 +186,7 @@ print_html.compare_parameters <- function(x, } # which engine? - engine <- insight::validate_argument( - getOption("easystats_html_engine", engine), - c("gt", "default", "tt") - ) + engine <- .check_format_backend(...) # line separator - for tinytable, we have no specific line separator, # because the output format is context-dependent @@ -261,7 +253,7 @@ print_html.compare_parameters <- function(x, out <- insight::export_table( formatted_table, - format = ifelse(identical(engine, "tt"), "tt", "html"), + format = engine, caption = caption, # TODO: get rid of NOTE subtitle = subtitle, footer = footer, @@ -297,14 +289,7 @@ print_html.parameters_efa <- function(x, sort = FALSE, threshold = NULL, labels = NULL, - engine = "gt", ...) { - # which engine? - engine <- insight::validate_argument( - getOption("easystats_html_engine", engine), - c("gt", "default", "tt") - ) - # extract attributes if (is.null(threshold)) { threshold <- attributes(x)$threshold @@ -313,9 +298,10 @@ print_html.parameters_efa <- function(x, x, threshold = threshold, sort = sort, - format = ifelse(identical(engine, "tt"), "tt", "html"), + format = "html", digits = digits, labels = labels, + backend = .check_format_backend(...), ... ) } @@ -325,12 +311,9 @@ print_html.parameters_pca <- print_html.parameters_efa #' @export -print_html.parameters_efa_summary <- function(x, digits = 3, engine = "gt", ...) { +print_html.parameters_efa_summary <- function(x, digits = 3, ...) { # html engine? - engine <- insight::validate_argument( - getOption("easystats_html_engine", engine), - c("gt", "default", "tt") - ) + engine <- .check_format_backend(...) table_caption <- "(Explained) Variance of Components" @@ -354,7 +337,7 @@ print_html.parameters_efa_summary <- function(x, digits = 3, engine = "gt", ...) insight::export_table( x, digits = digits, - format = ifelse(identical(engine, "tt"), "tt", "html"), + format = engine, caption = table_caption, align = "firstleft" ) @@ -372,7 +355,6 @@ print_html.parameters_p_function <- function(x, ci_width = "auto", ci_brackets = c("(", ")"), pretty_names = TRUE, - engine = "gt", ...) { .print_p_function( x, @@ -381,7 +363,7 @@ print_html.parameters_p_function <- function(x, ci_brackets, pretty_names, format = "html", - engine = engine, + backend = .check_format_backend(...), ... ) } @@ -457,3 +439,14 @@ print_html.parameters_p_function <- function(x, ) out } + + +# we allow exporting HTML format based on "gt" or "tinytable" +.check_format_backend <- function(...) { + dots <- list(...) + if (is.null(dots) || !identical(dots$backend, "tt")) { + "html" + } else { + "tt" + } +} diff --git a/R/standardize_parameters.R b/R/standardize_parameters.R index 4bada328b..1ba487ca5 100644 --- a/R/standardize_parameters.R +++ b/R/standardize_parameters.R @@ -549,14 +549,12 @@ print_md.parameters_standardized <- function(x, digits = 2, ...) { } #' @export -print_html.parameters_standardized <- function(x, digits = 2, engine = "gt", ...) { +print_html.parameters_standardized <- function(x, digits = 2, ...) { # which engine? - engine <- insight::validate_argument( - getOption("easystats_html_engine", engine), - c("gt", "default", "tt") - ) + engine <- .check_format_backend(...) + x_fmt <- format(x, digits = digits, output = "html", ...) - insight::export_table(x_fmt, format = ifelse(identical(engine, "tt"), "tt", "html"), ...) + insight::export_table(x_fmt, format = engine, ...) } diff --git a/R/utils_pca_efa.R b/R/utils_pca_efa.R index 4f2ce030c..3b008e1c7 100644 --- a/R/utils_pca_efa.R +++ b/R/utils_pca_efa.R @@ -363,12 +363,9 @@ print.parameters_omega_summary <- function(x, ...) { } -.print_parameters_cfa_efa <- function(x, threshold, sort, format, digits, labels, engine = "gt", ...) { +.print_parameters_cfa_efa <- function(x, threshold, sort, format, digits, labels, ...) { # html engine? - engine <- insight::validate_argument( - getOption("easystats_html_engine", engine), - c("gt", "default", "tt") - ) + engine <- .check_format_backend(...) # Method if (inherits(x, "parameters_pca")) { From c9c6d23645d6fdba9901fe97922ced58b028321a Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 22 Jul 2025 00:07:08 +0200 Subject: [PATCH 2/5] fix --- R/print_html.R | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/R/print_html.R b/R/print_html.R index 7c348b74d..cf8e642b6 100644 --- a/R/print_html.R +++ b/R/print_html.R @@ -301,7 +301,6 @@ print_html.parameters_efa <- function(x, format = "html", digits = digits, labels = labels, - backend = .check_format_backend(...), ... ) } @@ -363,7 +362,6 @@ print_html.parameters_p_function <- function(x, ci_brackets, pretty_names, format = "html", - backend = .check_format_backend(...), ... ) } @@ -444,9 +442,9 @@ print_html.parameters_p_function <- function(x, # we allow exporting HTML format based on "gt" or "tinytable" .check_format_backend <- function(...) { dots <- list(...) - if (is.null(dots) || !identical(dots$backend, "tt")) { - "html" - } else { + if (identical(dots$backend, "tt")) { "tt" + } else { + "html" } } From ef177816da9f5738523afe00d0c65dc7c06ffb4f Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 22 Jul 2025 00:24:53 +0200 Subject: [PATCH 3/5] docs --- man/print.compare_parameters.Rd | 1 - man/print.parameters_model.Rd | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/man/print.compare_parameters.Rd b/man/print.compare_parameters.Rd index 75da32d19..aeb501451 100644 --- a/man/print.compare_parameters.Rd +++ b/man/print.compare_parameters.Rd @@ -56,7 +56,6 @@ font_size = "100\%", line_padding = 4, column_labels = NULL, - engine = "gt", ... ) diff --git a/man/print.parameters_model.Rd b/man/print.parameters_model.Rd index c2cfa4105..6bebb8e7a 100644 --- a/man/print.parameters_model.Rd +++ b/man/print.parameters_model.Rd @@ -71,7 +71,6 @@ line_padding = 4, column_labels = NULL, include_reference = FALSE, - engine = "gt", verbose = TRUE, ... ) @@ -244,6 +243,8 @@ data frames, \code{caption} may be a list of table captions, one for each table. \item{column_labels}{Labels of columns for HTML tables. If \code{NULL}, automatic column names are generated. See 'Examples'.} +\item{verbose}{Toggle messages and warnings.} + \item{engine}{Character string, naming the package or engine to be used for printing into HTML or markdown format. Currently supported \code{"gt"} (or \code{"default"}) to use the \emph{gt} package to print to HTML and the default easystats @@ -251,8 +252,6 @@ engine to create markdown tables. If \code{engine = "tt"}, the \emph{tinytable} is used for printing to HTML or markdown. Not all \code{print()} methods support the \code{"tt"} engine yet. If a specific \code{print()} method has no \code{engine} argument, \code{insight::export_table()} is used, which uses \emph{gt} for HTML printing.} - -\item{verbose}{Toggle messages and warnings.} } \value{ Invisibly returns the original input object. From ceeae7cd8d1e9903ce5d13681def66c56d8ce416 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 22 Jul 2025 00:32:53 +0200 Subject: [PATCH 4/5] docs --- R/print.parameters_model.R | 7 ------- man/print.compare_parameters.Rd | 8 -------- man/print.parameters_model.Rd | 8 -------- 3 files changed, 23 deletions(-) diff --git a/R/print.parameters_model.R b/R/print.parameters_model.R index a49554c94..766e2cf59 100644 --- a/R/print.parameters_model.R +++ b/R/print.parameters_model.R @@ -99,13 +99,6 @@ #' categorical predictors. The coefficient for the reference level is always #' `0` (except when `exponentiate = TRUE`, then the coefficient will be `1`), #' so this is just for completeness. -#' @param engine Character string, naming the package or engine to be used for -#' printing into HTML or markdown format. Currently supported `"gt"` (or -#' `"default"`) to use the *gt* package to print to HTML and the default easystats -#' engine to create markdown tables. If `engine = "tt"`, the *tinytable* package -#' is used for printing to HTML or markdown. Not all `print()` methods support -#' the `"tt"` engine yet. If a specific `print()` method has no `engine` argument, -#' `insight::export_table()` is used, which uses *gt* for HTML printing. #' @param ... Arguments passed down to [`format.parameters_model()`], #' [`insight::format_table()`] and [`insight::export_table()`] #' @inheritParams insight::format_table diff --git a/man/print.compare_parameters.Rd b/man/print.compare_parameters.Rd index aeb501451..b695df004 100644 --- a/man/print.compare_parameters.Rd +++ b/man/print.compare_parameters.Rd @@ -168,14 +168,6 @@ variables, see 'Examples'. Parameters will be re-ordered according to the order used in \code{groups}, while all non-matching parameters will be added to the end.} -\item{engine}{Character string, naming the package or engine to be used for -printing into HTML or markdown format. Currently supported \code{"gt"} (or -\code{"default"}) to use the \emph{gt} package to print to HTML and the default easystats -engine to create markdown tables. If \code{engine = "tt"}, the \emph{tinytable} package -is used for printing to HTML or markdown. Not all \code{print()} methods support -the \code{"tt"} engine yet. If a specific \code{print()} method has no \code{engine} argument, -\code{insight::export_table()} is used, which uses \emph{gt} for HTML printing.} - \item{...}{Arguments passed down to \code{\link[=format.parameters_model]{format.parameters_model()}}, \code{\link[insight:format_table]{insight::format_table()}} and \code{\link[insight:export_table]{insight::export_table()}}} diff --git a/man/print.parameters_model.Rd b/man/print.parameters_model.Rd index 6bebb8e7a..6a5213f6e 100644 --- a/man/print.parameters_model.Rd +++ b/man/print.parameters_model.Rd @@ -244,14 +244,6 @@ data frames, \code{caption} may be a list of table captions, one for each table. column names are generated. See 'Examples'.} \item{verbose}{Toggle messages and warnings.} - -\item{engine}{Character string, naming the package or engine to be used for -printing into HTML or markdown format. Currently supported \code{"gt"} (or -\code{"default"}) to use the \emph{gt} package to print to HTML and the default easystats -engine to create markdown tables. If \code{engine = "tt"}, the \emph{tinytable} package -is used for printing to HTML or markdown. Not all \code{print()} methods support -the \code{"tt"} engine yet. If a specific \code{print()} method has no \code{engine} argument, -\code{insight::export_table()} is used, which uses \emph{gt} for HTML printing.} } \value{ Invisibly returns the original input object. From 4630af3e31ce6a89e9ed32d0143d03e69da271b6 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 22 Jul 2025 00:44:51 +0200 Subject: [PATCH 5/5] update rd --- R/display.R | 8 ++++---- R/format.R | 1 - R/print.parameters_model.R | 4 ---- R/standardize_parameters.R | 3 ++- man/display.parameters_model.Rd | 8 ++++---- man/model_parameters.Rd | 3 --- man/print.compare_parameters.Rd | 4 ---- man/print.parameters_model.Rd | 3 --- 8 files changed, 10 insertions(+), 24 deletions(-) diff --git a/R/display.R b/R/display.R index f978a3e08..ab4cf812d 100644 --- a/R/display.R +++ b/R/display.R @@ -2,10 +2,10 @@ #' @name display.parameters_model #' #' @description Prints tables (i.e. data frame) in different output formats. -#' `print_md()` is an alias for `display(format = "markdown")`, `print_html()` -#' is an alias for `display(format = "html")`, and `print_html(engine = "tt")` -#' is an alias for `display(format = "tt")`. The latter is a `tinytable` object, -#' which is either printed as markdown or HTML table, depending on the environment. +#' `print_md()` is an alias for `display(format = "markdown")` and +#' `print_html()` is an alias for `display(format = "html")`. A third option is +#' `display(format = "tt")`, which returns a `tinytable` object, which is either +#' printed as markdown or HTML table, depending on the environment. #' #' @param object An object returned by one of the package's function, for example #' [`model_parameters()`], [`simulate_parameters()`], [`equivalence_test()`] or diff --git a/R/format.R b/R/format.R index c2ca52467..b8c3bf9fe 100644 --- a/R/format.R +++ b/R/format.R @@ -224,7 +224,6 @@ format.compare_parameters <- function(x, zap_small = FALSE, format = NULL, groups = NULL, - engine = NULL, ...) { m_class <- attributes(x)$model_class x$Method <- NULL diff --git a/R/print.parameters_model.R b/R/print.parameters_model.R index 766e2cf59..e07692fc7 100644 --- a/R/print.parameters_model.R +++ b/R/print.parameters_model.R @@ -154,10 +154,6 @@ #' output, like markdown files). The argument `table_width` can also be used in #' most `print()` methods to specify the table width as desired. #' -#' - `easystats_html_engine`: `options(easystats_html_engine = "gt")` will set -#' the default HTML engine for tables to `gt`, i.e. the _gt_ package is used to -#' create HTML tables. If set to `tt`, the _tinytable_ package is used. -#' #' - `insight_use_symbols`: `options(insight_use_symbols = TRUE)` will try to #' print unicode-chars for symbols as column names, wherever possible (e.g., #' \ifelse{html}{\out{ω}}{\eqn{\omega}} instead of `Omega`). diff --git a/R/standardize_parameters.R b/R/standardize_parameters.R index 1ba487ca5..9fcc07220 100644 --- a/R/standardize_parameters.R +++ b/R/standardize_parameters.R @@ -525,9 +525,10 @@ display.parameters_standardized <- function(object, digits = 2, ...) { format <- insight::validate_argument(format, c("markdown", "html", "md", "tt")) - fun_args <- list(x = object, digits = digits, engine = ifelse(format == "tt", "tt", "gt")) + fun_args <- list(x = object, digits = digits) if (format %in% c("html", "tt")) { + fun_args$backend <- format do.call(print_html, c(fun_args, list(...))) } else { do.call(print_md, c(fun_args, list(...))) diff --git a/man/display.parameters_model.Rd b/man/display.parameters_model.Rd index 942ac5ad9..70fa27a15 100644 --- a/man/display.parameters_model.Rd +++ b/man/display.parameters_model.Rd @@ -202,10 +202,10 @@ class \code{gt_tbl}. If \code{format = "tt"}, an object of class \code{tinytable } \description{ Prints tables (i.e. data frame) in different output formats. -\code{print_md()} is an alias for \code{display(format = "markdown")}, \code{print_html()} -is an alias for \code{display(format = "html")}, and \code{print_html(engine = "tt")} -is an alias for \code{display(format = "tt")}. The latter is a \code{tinytable} object, -which is either printed as markdown or HTML table, depending on the environment. +\code{print_md()} is an alias for \code{display(format = "markdown")} and +\code{print_html()} is an alias for \code{display(format = "html")}. A third option is +\code{display(format = "tt")}, which returns a \code{tinytable} object, which is either +printed as markdown or HTML table, depending on the environment. } \details{ \code{display()} is useful when the table-output from functions, diff --git a/man/model_parameters.Rd b/man/model_parameters.Rd index e4a672282..769e191cb 100644 --- a/man/model_parameters.Rd +++ b/man/model_parameters.Rd @@ -446,9 +446,6 @@ printed to console. If not specified, tables will be adjusted to the current available width, e.g. of the of the console (or any other source for textual output, like markdown files). The argument \code{table_width} can also be used in most \code{print()} methods to specify the table width as desired. -\item \code{easystats_html_engine}: \code{options(easystats_html_engine = "gt")} will set -the default HTML engine for tables to \code{gt}, i.e. the \emph{gt} package is used to -create HTML tables. If set to \code{tt}, the \emph{tinytable} package is used. \item \code{insight_use_symbols}: \code{options(insight_use_symbols = TRUE)} will try to print unicode-chars for symbols as column names, wherever possible (e.g., \ifelse{html}{\out{ω}}{\eqn{\omega}} instead of \code{Omega}). diff --git a/man/print.compare_parameters.Rd b/man/print.compare_parameters.Rd index b695df004..d8453d74e 100644 --- a/man/print.compare_parameters.Rd +++ b/man/print.compare_parameters.Rd @@ -20,7 +20,6 @@ zap_small = FALSE, format = NULL, groups = NULL, - engine = NULL, ... ) @@ -245,9 +244,6 @@ printed to console. If not specified, tables will be adjusted to the current available width, e.g. of the of the console (or any other source for textual output, like markdown files). The argument \code{table_width} can also be used in most \code{print()} methods to specify the table width as desired. -\item \code{easystats_html_engine}: \code{options(easystats_html_engine = "gt")} will set -the default HTML engine for tables to \code{gt}, i.e. the \emph{gt} package is used to -create HTML tables. If set to \code{tt}, the \emph{tinytable} package is used. \item \code{insight_use_symbols}: \code{options(insight_use_symbols = TRUE)} will try to print unicode-chars for symbols as column names, wherever possible (e.g., \ifelse{html}{\out{ω}}{\eqn{\omega}} instead of \code{Omega}). diff --git a/man/print.parameters_model.Rd b/man/print.parameters_model.Rd index 6a5213f6e..97baa7fd3 100644 --- a/man/print.parameters_model.Rd +++ b/man/print.parameters_model.Rd @@ -296,9 +296,6 @@ printed to console. If not specified, tables will be adjusted to the current available width, e.g. of the of the console (or any other source for textual output, like markdown files). The argument \code{table_width} can also be used in most \code{print()} methods to specify the table width as desired. -\item \code{easystats_html_engine}: \code{options(easystats_html_engine = "gt")} will set -the default HTML engine for tables to \code{gt}, i.e. the \emph{gt} package is used to -create HTML tables. If set to \code{tt}, the \emph{tinytable} package is used. \item \code{insight_use_symbols}: \code{options(insight_use_symbols = TRUE)} will try to print unicode-chars for symbols as column names, wherever possible (e.g., \ifelse{html}{\out{ω}}{\eqn{\omega}} instead of \code{Omega}).