Skip to content

Commit 52799c0

Browse files
committed
add print_html method
1 parent 02847e8 commit 52799c0

File tree

5 files changed

+94
-56
lines changed

5 files changed

+94
-56
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ S3method(print,parameters_sem)
613613
S3method(print,parameters_simulate)
614614
S3method(print,parameters_standardized)
615615
S3method(print_html,compare_parameters)
616+
S3method(print_html,equivalence_test_lm)
616617
S3method(print_html,parameters_brms_meta)
617618
S3method(print_html,parameters_efa)
618619
S3method(print_html,parameters_efa_summary)

R/equivalence_test.R

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,3 +854,73 @@ plot.equivalence_test_lm <- function(x, ...) {
854854
insight::check_if_installed("see")
855855
NextMethod()
856856
}
857+
858+
859+
# helper for print_html / print_md --------------------
860+
861+
.print_equivalence_test_lm <- function(
862+
x,
863+
digits = 2,
864+
ci_brackets = c("(", ")"),
865+
zap_small = FALSE,
866+
format = "markdown",
867+
...
868+
) {
869+
rule <- attributes(x)$rule
870+
rope <- attributes(x)$rope
871+
872+
if (is.null(rule)) {
873+
table_caption <- "Test for Practical Equivalence"
874+
} else if (rule == "cet") {
875+
table_caption <- "Conditional Equivalence Testing"
876+
} else if (rule == "classic") {
877+
table_caption <- "TOST-test for Practical Equivalence"
878+
} else {
879+
table_caption <- "Test for Practical Equivalence"
880+
}
881+
882+
if ("Component" %in% colnames(x)) {
883+
x <- x[x$Component %in% c("conditional", "count"), ]
884+
}
885+
886+
formatted_table <- insight::format_table(
887+
x,
888+
pretty_names = TRUE,
889+
digits = digits,
890+
ci_width = NULL,
891+
ci_brackets = ci_brackets,
892+
zap_small = zap_small,
893+
...
894+
)
895+
896+
colnames(formatted_table)[which(colnames(formatted_table) == "Equivalence (ROPE)")] <- "H0"
897+
formatted_table$ROPE <- NULL
898+
899+
# col_order <- c("Parameter", "H0", "% in ROPE", colnames(formatted_table)[grepl(" CI$", colnames(formatted_table))])
900+
# col_order <- c(col_order, setdiff(colnames(formatted_table), col_order))
901+
# formatted_table <- formatted_table[col_order]
902+
903+
# replace brackets by parenthesis
904+
if (!is.null(ci_brackets) && "Parameter" %in% colnames(formatted_table)) {
905+
formatted_table$Parameter <- gsub("[", ci_brackets[1], formatted_table$Parameter, fixed = TRUE)
906+
formatted_table$Parameter <- gsub("]", ci_brackets[2], formatted_table$Parameter, fixed = TRUE)
907+
}
908+
909+
if (!is.null(rope)) {
910+
names(formatted_table)[names(formatted_table) == "% in ROPE"] <- sprintf(
911+
"%% in ROPE (%.*f, %.*f)",
912+
digits,
913+
rope[1],
914+
digits,
915+
rope[2]
916+
) # nolint
917+
}
918+
919+
insight::export_table(
920+
formatted_table,
921+
format = format,
922+
caption = table_caption,
923+
align = "firstleft",
924+
...
925+
)
926+
}

R/print.parameters_model.R

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,6 @@
101101
#' so this is just for completeness.
102102
#' @param align Only applies to HTML tables. May be one of `"left"`,
103103
#' `"right"` or `"center"`.
104-
#' @param digits,ci_digits,p_digits Number of digits for rounding or
105-
#' significant figures. May also be `"signif"` to return significant
106-
#' figures or `"scientific"` to return scientific notation. Control the
107-
#' number of digits by adding the value as suffix, e.g. `digits = "scientific4"`
108-
#' to have scientific notation with 4 decimal places, or `digits = "signif5"`
109-
#' for 5 significant figures (see also [signif()]).
110104
#' @param subtitle Table title (same as caption) and subtitle, as strings. If `NULL`,
111105
#' no title or subtitle is printed, unless it is stored as attributes (`table_title`,
112106
#' or its alias `table_caption`, and `table_subtitle`). If `x` is a list of

R/print_html.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,27 @@ print_html.parameters_efa_summary <- function(x, digits = 3, ...) {
347347
print_html.parameters_pca_summary <- print_html.parameters_efa_summary
348348

349349

350+
# Equivalence test ----------------------------
351+
352+
#' @export
353+
print_html.equivalence_test_lm <- function(
354+
x,
355+
digits = 2,
356+
ci_brackets = c("(", ")"),
357+
zap_small = FALSE,
358+
...
359+
) {
360+
.print_equivalence_test_lm(
361+
x,
362+
digits = digits,
363+
ci_brackets = ci_brackets,
364+
zap_small = zap_small,
365+
format = .check_format_backend(...),
366+
...
367+
)
368+
}
369+
370+
350371
# p_function ----------------------------
351372

352373
#' @rdname p_function

R/print_md.R

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -295,61 +295,13 @@ print_md.equivalence_test_lm <- function(
295295
zap_small = FALSE,
296296
...
297297
) {
298-
rule <- attributes(x)$rule
299-
rope <- attributes(x)$rope
300-
301-
if (is.null(rule)) {
302-
table_caption <- "Test for Practical Equivalence"
303-
} else if (rule == "cet") {
304-
table_caption <- "Conditional Equivalence Testing"
305-
} else if (rule == "classic") {
306-
table_caption <- "TOST-test for Practical Equivalence"
307-
} else {
308-
table_caption <- "Test for Practical Equivalence"
309-
}
310-
311-
if ("Component" %in% colnames(x)) {
312-
x <- x[x$Component %in% c("conditional", "count"), ]
313-
}
314-
315-
formatted_table <- insight::format_table(
298+
.print_equivalence_test_lm(
316299
x,
317-
pretty_names = TRUE,
318300
digits = digits,
319-
ci_width = NULL,
320301
ci_brackets = ci_brackets,
321302
zap_small = zap_small,
322-
...
323-
)
324-
325-
colnames(formatted_table)[which(colnames(formatted_table) == "Equivalence (ROPE)")] <- "H0"
326-
formatted_table$ROPE <- NULL
327-
328-
# col_order <- c("Parameter", "H0", "% in ROPE", colnames(formatted_table)[grepl(" CI$", colnames(formatted_table))])
329-
# col_order <- c(col_order, setdiff(colnames(formatted_table), col_order))
330-
# formatted_table <- formatted_table[col_order]
331-
332-
# replace brackets by parenthesis
333-
if (!is.null(ci_brackets) && "Parameter" %in% colnames(formatted_table)) {
334-
formatted_table$Parameter <- gsub("[", ci_brackets[1], formatted_table$Parameter, fixed = TRUE)
335-
formatted_table$Parameter <- gsub("]", ci_brackets[2], formatted_table$Parameter, fixed = TRUE)
336-
}
337-
338-
if (!is.null(rope)) {
339-
names(formatted_table)[names(formatted_table) == "% in ROPE"] <- sprintf(
340-
"%% in ROPE (%.*f, %.*f)",
341-
digits,
342-
rope[1],
343-
digits,
344-
rope[2]
345-
) # nolint
346-
}
347-
348-
insight::export_table(
349-
formatted_table,
350303
format = "markdown",
351-
caption = table_caption,
352-
align = "firstleft"
304+
...
353305
)
354306
}
355307

0 commit comments

Comments
 (0)