Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Feb 8, 2025
1 parent add6c4b commit d1ee9c3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
5 changes: 3 additions & 2 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#' @export
format.estimate_contrasts <- function(x,
format = NULL,
select = getOption("modelbased_select", NULL),
include_grid = getOption("modelbased_include_grid", FALSE),
...) {
# don't print columns of adjusted_for variables
Expand Down Expand Up @@ -60,9 +61,9 @@ format.estimate_contrasts <- function(x,
x <- datawizard::remove_empty_columns(x)

if (!is.null(format) && format %in% c("md", "markdown", "html")) {
insight::format_table(x, ci_brackets = c("(", ")"), ...)
insight::format_table(x, ci_brackets = c("(", ")"), select = select, format = "html", ...)
} else {
insight::format_table(x, ...)
insight::format_table(x, select = select, ...)
}
}

Expand Down
13 changes: 4 additions & 9 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#' of tables.
#'
#' @param x An object returned by the different `estimate_*()` functions.
#' @param select Character string, indicating which columns should be included
#' in the table.
#' @param include_grid Logical, if `TRUE`, the data grid is included in the
#' table output. Only applies to prediction-functions like `estimate_relation()`
#' or `estimate_link()`.
Expand All @@ -14,6 +12,8 @@
#' @param ... Arguments passed to `insight::format_table()` or
#' `insight::export_table()`.
#'
#' @inheritParams insight::format_table
#'
#' @return Invisibly returns `x`.
#'
#' @section Global Options to Customize Tables when Printing:
Expand Down Expand Up @@ -51,14 +51,9 @@ print.estimate_contrasts <- function(x,
attr <- attributes(x)
attr <- attr[setdiff(names(attr), c("names", "row.names"))]

# select columns to print
if (!is.null(select)) {
out <- .format_layout(out, select)
attributes(out) <- utils::modifyList(attributes(out), attr)
}

# format table
out <- format(out, include_grid = include_grid, ...)
out <- format(out, select = select, include_grid = include_grid, ...)
attributes(out) <- utils::modifyList(attributes(out), attr)

# remove redundant labels, for "by" variables
out <- .remove_redundant_labels(x, out, full_labels)
Expand Down
43 changes: 41 additions & 2 deletions man/print.estimate_contrasts.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-print.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ test_that("print - layouts and include data grid", {
model <- lm(Petal.Length ~ Species, data = iris)
out <- estimate_means(model, "Species")
expect_snapshot(print(out))
expect_snapshot(print(out, select = "basic"))
expect_snapshot(print(out, select = "minimal"))

m <- lm(wt ~ qsec + mpg, dat = mtcars)
expect_snapshot(print(estimate_relation(m, by = "qsec")))
Expand Down

0 comments on commit d1ee9c3

Please sign in to comment.