diff --git a/R/display.R b/R/display.R index fbc920028..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 @@ -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/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/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.parameters_model.R b/R/print.parameters_model.R index a49554c94..e07692fc7 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 @@ -161,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/print_html.R b/R/print_html.R index 84385ed17..cf8e642b6 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,7 +298,7 @@ print_html.parameters_efa <- function(x, x, threshold = threshold, sort = sort, - format = ifelse(identical(engine, "tt"), "tt", "html"), + format = "html", digits = digits, labels = labels, ... @@ -325,12 +310,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 +336,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 +354,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 +362,6 @@ print_html.parameters_p_function <- function(x, ci_brackets, pretty_names, format = "html", - engine = engine, ... ) } @@ -457,3 +437,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 (identical(dots$backend, "tt")) { + "tt" + } else { + "html" + } +} diff --git a/R/standardize_parameters.R b/R/standardize_parameters.R index 4bada328b..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(...))) @@ -549,14 +550,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")) { 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 75da32d19..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, ... ) @@ -56,7 +55,6 @@ font_size = "100\%", line_padding = 4, column_labels = NULL, - engine = "gt", ... ) @@ -169,14 +167,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()}}} @@ -254,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 c2cfa4105..97baa7fd3 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,14 +243,6 @@ 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{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{verbose}{Toggle messages and warnings.} } \value{ @@ -305,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}).