Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions R/display.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -138,7 +138,7 @@
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(...)))
Expand Down Expand Up @@ -189,7 +189,7 @@
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(...)))
Expand Down Expand Up @@ -219,7 +219,7 @@
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")) {
Expand All @@ -237,7 +237,7 @@
#' @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(...)))
Expand All @@ -256,7 +256,7 @@
#' @inheritParams model_parameters.principal
#' @rdname display.parameters_model
#' @export
display.parameters_efa <- function(object, format = "markdown", digits = 2, sort = FALSE, threshold = NULL, labels = NULL, ...) {

Check warning on line 259 in R/display.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/display.R,line=259,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 129 characters.
format <- insight::validate_argument(format, c("markdown", "html", "md", "tt"))

fun_args <- list(
Expand All @@ -265,7 +265,7 @@
sort = sort,
threshold = threshold,
labels = labels,
engine = ifelse(format == "tt", "tt", "gt")
backend = ifelse(format == "tt", "tt", "html")
)

if (format %in% c("html", "tt")) {
Expand Down Expand Up @@ -310,7 +310,7 @@
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")) {
Expand Down
1 change: 0 additions & 1 deletion R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @inheritParams print.parameters_model
#' @rdname print.parameters_model
#' @export
format.parameters_model <- function(x,

Check warning on line 6 in R/format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/format.R,line=6,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this expression from 67 to at most 40.
pretty_names = TRUE,
split_components = TRUE,
select = NULL,
Expand Down Expand Up @@ -170,7 +170,7 @@
# remove unique columns
if (insight::has_single_value(formatted_table$Component, remove_na = TRUE)) formatted_table$Component <- NULL
if (insight::has_single_value(formatted_table$Effects, remove_na = TRUE)) formatted_table$Effects <- NULL
if (insight::has_single_value(formatted_table$Group, remove_na = TRUE) && isTRUE(mixed_model)) formatted_table$Group <- NULL

Check warning on line 173 in R/format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/format.R,line=173,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 126 characters.

# no column with CI-level in output
if (!is.null(formatted_table$CI) && insight::has_single_value(formatted_table$CI, remove_na = TRUE)) {
Expand Down Expand Up @@ -213,7 +213,7 @@
#' @rdname print.compare_parameters
#' @inheritParams print.parameters_model
#' @export
format.compare_parameters <- function(x,

Check warning on line 216 in R/format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/format.R,line=216,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this expression from 41 to at most 40.
split_components = TRUE,
select = NULL,
digits = 2,
Expand All @@ -224,7 +224,6 @@
zap_small = FALSE,
format = NULL,
groups = NULL,
engine = NULL,
...) {
m_class <- attributes(x)$model_class
x$Method <- NULL
Expand Down Expand Up @@ -681,7 +680,7 @@


# footer: type of uncertainty interval
.print_footer_cimethod <- function(x) {

Check warning on line 683 in R/format.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/format.R,line=683,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this expression from 46 to at most 40.
if (isTRUE(getOption("parameters_cimethod", TRUE))) {
# get attributes
ci_method <- .additional_arguments(x, "ci_method", NULL)
Expand Down
6 changes: 1 addition & 5 deletions R/p_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
#' A non-significant p-value could occur because the test hypothesis is false,
#' but could also be the result of any of the model assumptions being incorrect.
#'
#' \if{html}{\cr \figure{unconditional_interpretation.png}{options: alt="Conditional versus unconditional interpretations of P-values"} \cr}

Check warning on line 80 in R/p_function.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/p_function.R,line=80,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 140 characters.
#'
#' "Emphasizing unconditional interpretations helps avoid overconfident and
#' misleading inferences in light of uncertainties about the assumptions used
Expand Down Expand Up @@ -443,13 +443,9 @@
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,
Expand Down
11 changes: 0 additions & 11 deletions R/print.parameters_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{&omega;}}{\eqn{\omega}} instead of `Omega`).
Expand Down
47 changes: 19 additions & 28 deletions R/print_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@
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
Expand Down Expand Up @@ -123,7 +119,7 @@

out <- insight::export_table(
formatted_table,
format = ifelse(identical(engine, "tt"), "tt", "html"),
format = engine,
caption = table_caption,
subtitle = subtitle,
footer = footer,
Expand Down Expand Up @@ -170,7 +166,6 @@
font_size = "100%",
line_padding = 4,
column_labels = NULL,
engine = "gt",
...) {
# check if user supplied digits attributes
if (missing(digits)) {
Expand All @@ -191,10 +186,7 @@
}

# 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
Expand Down Expand Up @@ -227,7 +219,7 @@
# --------------------------------------------------------------------------

model_groups <- NULL
by <- NULL

Check warning on line 222 in R/print_html.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/print_html.R,line=222,col=3,[object_overwrite_linter] 'by' is an exported object from package 'base'. Avoid re-using such symbols.

# find columns that contain model names, which we want to group
models <- setdiff(
Expand All @@ -251,17 +243,17 @@
}
}
if ("Component" %in% colnames(formatted_table)) {
by <- c(by, "Component")

Check warning on line 246 in R/print_html.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/print_html.R,line=246,col=5,[object_overwrite_linter] 'by' is an exported object from package 'base'. Avoid re-using such symbols.
}
if ("Effects" %in% colnames(formatted_table)) {
by <- c(by, "Effects")

Check warning on line 249 in R/print_html.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/print_html.R,line=249,col=5,[object_overwrite_linter] 'by' is an exported object from package 'base'. Avoid re-using such symbols.
}

# export table ------------------------------------------------------------

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,
Expand Down Expand Up @@ -297,14 +289,7 @@
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
Expand All @@ -313,7 +298,7 @@
x,
threshold = threshold,
sort = sort,
format = ifelse(identical(engine, "tt"), "tt", "html"),
format = "html",
digits = digits,
labels = labels,
...
Expand All @@ -325,12 +310,9 @@


#' @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"

Expand All @@ -354,7 +336,7 @@
insight::export_table(
x,
digits = digits,
format = ifelse(identical(engine, "tt"), "tt", "html"),
format = engine,
caption = table_caption,
align = "firstleft"
)
Expand All @@ -372,7 +354,6 @@
ci_width = "auto",
ci_brackets = c("(", ")"),
pretty_names = TRUE,
engine = "gt",
...) {
.print_p_function(
x,
Expand All @@ -381,7 +362,6 @@
ci_brackets,
pretty_names,
format = "html",
engine = engine,
...
)
}
Expand Down Expand Up @@ -457,3 +437,14 @@
)
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"
}
}
13 changes: 6 additions & 7 deletions R/standardize_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
#' @family standardize
#' @family effect size indices
#'
#' @seealso See also [package vignette](https://easystats.github.io/parameters/articles/standardize_parameters_effsize.html).

Check warning on line 128 in R/standardize_parameters.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/standardize_parameters.R,line=128,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.
#'
#' @examples
#' model <- lm(len ~ supp * dose, data = ToothGrowth)
Expand Down Expand Up @@ -525,9 +525,10 @@
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(...)))
Expand All @@ -549,14 +550,12 @@
}

#' @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, ...)
}


Expand Down
7 changes: 2 additions & 5 deletions R/utils_pca_efa.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
8 changes: 4 additions & 4 deletions man/display.parameters_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions man/model_parameters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions man/print.compare_parameters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions man/print.parameters_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading