Skip to content

Commit bb0a633

Browse files
authored
Purely internal need (#1143)
* Purely internal need * fix * docs * docs * update rd
1 parent f0ece7d commit bb0a633

11 files changed

+42
-99
lines changed

R/display.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#' @name display.parameters_model
33
#'
44
#' @description Prints tables (i.e. data frame) in different output formats.
5-
#' `print_md()` is an alias for `display(format = "markdown")`, `print_html()`
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.
5+
#' `print_md()` is an alias for `display(format = "markdown")` and
6+
#' `print_html()` is an alias for `display(format = "html")`. A third option is
7+
#' `display(format = "tt")`, which returns a `tinytable` object, which is either
8+
#' printed as markdown or HTML table, depending on the environment.
99
#'
1010
#' @param object An object returned by one of the package's function, for example
1111
#' [`model_parameters()`], [`simulate_parameters()`], [`equivalence_test()`] or
@@ -138,7 +138,7 @@ display.parameters_model <- function(object,
138138
align = align,
139139
font_size = font_size,
140140
line_padding = line_padding,
141-
engine = ifelse(format == "tt", "tt", "gt")
141+
backend = ifelse(format == "tt", "tt", "html")
142142
)
143143
)
144144
do.call(print_html, c(fun_args, list(...)))
@@ -189,7 +189,7 @@ display.compare_parameters <- function(object,
189189
column_labels = column_labels,
190190
font_size = font_size,
191191
line_padding = line_padding,
192-
engine = ifelse(format == "tt", "tt", "gt")
192+
backend = ifelse(format == "tt", "tt", "html")
193193
)
194194
)
195195
do.call(print_html, c(fun_args, list(...)))
@@ -219,7 +219,7 @@ display.parameters_sem <- function(object,
219219
ci_digits = ci_digits,
220220
p_digits = p_digits,
221221
ci_brackets = ci_brackets,
222-
engine = ifelse(format == "tt", "tt", "gt")
222+
backend = ifelse(format == "tt", "tt", "html")
223223
)
224224

225225
if (format %in% c("html", "tt")) {
@@ -237,7 +237,7 @@ display.parameters_sem <- function(object,
237237
#' @export
238238
display.parameters_efa_summary <- function(object, format = "markdown", digits = 3, ...) {
239239
format <- insight::validate_argument(format, c("markdown", "html", "md", "tt"))
240-
fun_args <- list(x = object, digits = digits, engine = ifelse(format == "tt", "tt", "gt"))
240+
fun_args <- list(x = object, digits = digits, backend = ifelse(format == "tt", "tt", "html"))
241241

242242
if (format %in% c("html", "tt")) {
243243
do.call(print_html, c(fun_args, list(...)))
@@ -265,7 +265,7 @@ display.parameters_efa <- function(object, format = "markdown", digits = 2, sort
265265
sort = sort,
266266
threshold = threshold,
267267
labels = labels,
268-
engine = ifelse(format == "tt", "tt", "gt")
268+
backend = ifelse(format == "tt", "tt", "html")
269269
)
270270

271271
if (format %in% c("html", "tt")) {
@@ -310,7 +310,7 @@ display.parameters_p_function <- function(object,
310310
ci_width = ci_width,
311311
ci_brackets = ci_brackets,
312312
pretty_names = pretty_names,
313-
engine = ifelse(format == "tt", "tt", "gt")
313+
backend = ifelse(format == "tt", "tt", "html")
314314
)
315315

316316
if (format %in% c("html", "tt")) {

R/format.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ format.compare_parameters <- function(x,
224224
zap_small = FALSE,
225225
format = NULL,
226226
groups = NULL,
227-
engine = NULL,
228227
...) {
229228
m_class <- attributes(x)$model_class
230229
x$Method <- NULL

R/p_function.R

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,9 @@ print.parameters_p_function <- function(x,
443443
ci_brackets = c("(", ")"),
444444
pretty_names = TRUE,
445445
format = "html",
446-
engine = "gt",
447446
...) {
448447
# which engine?
449-
engine <- insight::validate_argument(
450-
getOption("easystats_html_engine", engine),
451-
c("gt", "default", "tt")
452-
)
448+
engine <- .check_format_backend(...)
453449

454450
formatted_table <- format(
455451
x,

R/print.parameters_model.R

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@
9999
#' categorical predictors. The coefficient for the reference level is always
100100
#' `0` (except when `exponentiate = TRUE`, then the coefficient will be `1`),
101101
#' so this is just for completeness.
102-
#' @param engine Character string, naming the package or engine to be used for
103-
#' printing into HTML or markdown format. Currently supported `"gt"` (or
104-
#' `"default"`) to use the *gt* package to print to HTML and the default easystats
105-
#' engine to create markdown tables. If `engine = "tt"`, the *tinytable* package
106-
#' is used for printing to HTML or markdown. Not all `print()` methods support
107-
#' the `"tt"` engine yet. If a specific `print()` method has no `engine` argument,
108-
#' `insight::export_table()` is used, which uses *gt* for HTML printing.
109102
#' @param ... Arguments passed down to [`format.parameters_model()`],
110103
#' [`insight::format_table()`] and [`insight::export_table()`]
111104
#' @inheritParams insight::format_table
@@ -161,10 +154,6 @@
161154
#' output, like markdown files). The argument `table_width` can also be used in
162155
#' most `print()` methods to specify the table width as desired.
163156
#'
164-
#' - `easystats_html_engine`: `options(easystats_html_engine = "gt")` will set
165-
#' the default HTML engine for tables to `gt`, i.e. the _gt_ package is used to
166-
#' create HTML tables. If set to `tt`, the _tinytable_ package is used.
167-
#'
168157
#' - `insight_use_symbols`: `options(insight_use_symbols = TRUE)` will try to
169158
#' print unicode-chars for symbols as column names, wherever possible (e.g.,
170159
#' \ifelse{html}{\out{&omega;}}{\eqn{\omega}} instead of `Omega`).

R/print_html.R

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ print_html.parameters_model <- function(x,
2323
line_padding = 4,
2424
column_labels = NULL,
2525
include_reference = FALSE,
26-
engine = "gt",
2726
verbose = TRUE,
2827
...) {
2928
# which engine?
30-
engine <- insight::validate_argument(
31-
getOption("easystats_html_engine", engine),
32-
c("gt", "default", "tt")
33-
)
29+
engine <- .check_format_backend(...)
3430

3531
# line separator - for tinytable, we have no specific line separator,
3632
# because the output format is context-dependent
@@ -123,7 +119,7 @@ print_html.parameters_model <- function(x,
123119

124120
out <- insight::export_table(
125121
formatted_table,
126-
format = ifelse(identical(engine, "tt"), "tt", "html"),
122+
format = engine,
127123
caption = table_caption,
128124
subtitle = subtitle,
129125
footer = footer,
@@ -170,7 +166,6 @@ print_html.compare_parameters <- function(x,
170166
font_size = "100%",
171167
line_padding = 4,
172168
column_labels = NULL,
173-
engine = "gt",
174169
...) {
175170
# check if user supplied digits attributes
176171
if (missing(digits)) {
@@ -191,10 +186,7 @@ print_html.compare_parameters <- function(x,
191186
}
192187

193188
# which engine?
194-
engine <- insight::validate_argument(
195-
getOption("easystats_html_engine", engine),
196-
c("gt", "default", "tt")
197-
)
189+
engine <- .check_format_backend(...)
198190

199191
# line separator - for tinytable, we have no specific line separator,
200192
# because the output format is context-dependent
@@ -261,7 +253,7 @@ print_html.compare_parameters <- function(x,
261253

262254
out <- insight::export_table(
263255
formatted_table,
264-
format = ifelse(identical(engine, "tt"), "tt", "html"),
256+
format = engine,
265257
caption = caption, # TODO: get rid of NOTE
266258
subtitle = subtitle,
267259
footer = footer,
@@ -297,14 +289,7 @@ print_html.parameters_efa <- function(x,
297289
sort = FALSE,
298290
threshold = NULL,
299291
labels = NULL,
300-
engine = "gt",
301292
...) {
302-
# which engine?
303-
engine <- insight::validate_argument(
304-
getOption("easystats_html_engine", engine),
305-
c("gt", "default", "tt")
306-
)
307-
308293
# extract attributes
309294
if (is.null(threshold)) {
310295
threshold <- attributes(x)$threshold
@@ -313,7 +298,7 @@ print_html.parameters_efa <- function(x,
313298
x,
314299
threshold = threshold,
315300
sort = sort,
316-
format = ifelse(identical(engine, "tt"), "tt", "html"),
301+
format = "html",
317302
digits = digits,
318303
labels = labels,
319304
...
@@ -325,12 +310,9 @@ print_html.parameters_pca <- print_html.parameters_efa
325310

326311

327312
#' @export
328-
print_html.parameters_efa_summary <- function(x, digits = 3, engine = "gt", ...) {
313+
print_html.parameters_efa_summary <- function(x, digits = 3, ...) {
329314
# html engine?
330-
engine <- insight::validate_argument(
331-
getOption("easystats_html_engine", engine),
332-
c("gt", "default", "tt")
333-
)
315+
engine <- .check_format_backend(...)
334316

335317
table_caption <- "(Explained) Variance of Components"
336318

@@ -354,7 +336,7 @@ print_html.parameters_efa_summary <- function(x, digits = 3, engine = "gt", ...)
354336
insight::export_table(
355337
x,
356338
digits = digits,
357-
format = ifelse(identical(engine, "tt"), "tt", "html"),
339+
format = engine,
358340
caption = table_caption,
359341
align = "firstleft"
360342
)
@@ -372,7 +354,6 @@ print_html.parameters_p_function <- function(x,
372354
ci_width = "auto",
373355
ci_brackets = c("(", ")"),
374356
pretty_names = TRUE,
375-
engine = "gt",
376357
...) {
377358
.print_p_function(
378359
x,
@@ -381,7 +362,6 @@ print_html.parameters_p_function <- function(x,
381362
ci_brackets,
382363
pretty_names,
383364
format = "html",
384-
engine = engine,
385365
...
386366
)
387367
}
@@ -457,3 +437,14 @@ print_html.parameters_p_function <- function(x,
457437
)
458438
out
459439
}
440+
441+
442+
# we allow exporting HTML format based on "gt" or "tinytable"
443+
.check_format_backend <- function(...) {
444+
dots <- list(...)
445+
if (identical(dots$backend, "tt")) {
446+
"tt"
447+
} else {
448+
"html"
449+
}
450+
}

R/standardize_parameters.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,10 @@ display.parameters_standardized <- function(object,
525525
digits = 2,
526526
...) {
527527
format <- insight::validate_argument(format, c("markdown", "html", "md", "tt"))
528-
fun_args <- list(x = object, digits = digits, engine = ifelse(format == "tt", "tt", "gt"))
528+
fun_args <- list(x = object, digits = digits)
529529

530530
if (format %in% c("html", "tt")) {
531+
fun_args$backend <- format
531532
do.call(print_html, c(fun_args, list(...)))
532533
} else {
533534
do.call(print_md, c(fun_args, list(...)))
@@ -549,14 +550,12 @@ print_md.parameters_standardized <- function(x, digits = 2, ...) {
549550
}
550551

551552
#' @export
552-
print_html.parameters_standardized <- function(x, digits = 2, engine = "gt", ...) {
553+
print_html.parameters_standardized <- function(x, digits = 2, ...) {
553554
# which engine?
554-
engine <- insight::validate_argument(
555-
getOption("easystats_html_engine", engine),
556-
c("gt", "default", "tt")
557-
)
555+
engine <- .check_format_backend(...)
556+
558557
x_fmt <- format(x, digits = digits, output = "html", ...)
559-
insight::export_table(x_fmt, format = ifelse(identical(engine, "tt"), "tt", "html"), ...)
558+
insight::export_table(x_fmt, format = engine, ...)
560559
}
561560

562561

R/utils_pca_efa.R

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,9 @@ print.parameters_omega_summary <- function(x, ...) {
363363
}
364364

365365

366-
.print_parameters_cfa_efa <- function(x, threshold, sort, format, digits, labels, engine = "gt", ...) {
366+
.print_parameters_cfa_efa <- function(x, threshold, sort, format, digits, labels, ...) {
367367
# html engine?
368-
engine <- insight::validate_argument(
369-
getOption("easystats_html_engine", engine),
370-
c("gt", "default", "tt")
371-
)
368+
engine <- .check_format_backend(...)
372369

373370
# Method
374371
if (inherits(x, "parameters_pca")) {

man/display.parameters_model.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/model_parameters.Rd

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/print.compare_parameters.Rd

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)