Skip to content

Commit

Permalink
tbl printing uses update_focus()
Browse files Browse the repository at this point in the history
  • Loading branch information
eutwt committed Jan 2, 2024
1 parent 92fdbba commit 1329a9e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/tbl-format-header.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tbl_format_header <- function(x, setup, ...) {
#' @export
tbl_format_header.tbl <- function(x, setup, ...) {
named_header <- setup$tbl_sum
focus <- attr(x, "pillar_focus")
focus <- setup$focus
if (!is.null(focus)) {
named_header <- c(named_header, "Focus columns" = collapse(tick_if_needed(focus)))
}
Expand Down
22 changes: 19 additions & 3 deletions R/tbl-format-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ tbl_format_setup.tbl <- function(x, width, ...,
rows_missing <- 0L
}

focus <- update_focus(focus, x)

# Header
tbl_sum <- tbl_sum(x)

Expand Down Expand Up @@ -169,10 +171,22 @@ tbl_format_setup.tbl <- function(x, width, ...,
extra_cols = extra_cols,
extra_cols_total = extra_cols_total,
max_footer_lines = max_footer_lines,
abbrev_cols = abbrev_cols
abbrev_cols = abbrev_cols,
focus = focus
)
}

update_focus <- function(focus, x) {
if (is_null(focus)) {
focus <- attr(x, "pillar_focus")
}
focus <- intersect(focus, names(x))
if (is_empty(focus)) {
return(NULL)
}
focus
}

#' Construct a setup object for formatting
#'
#' @description
Expand Down Expand Up @@ -207,7 +221,8 @@ new_tbl_format_setup <- function(x, df, width, tbl_sum, body,
rows_missing, rows_total,
extra_cols, extra_cols_total,
max_footer_lines,
abbrev_cols) {
abbrev_cols,
focus) {
trunc_info <- list(
x = x,
df = df,
Expand All @@ -219,7 +234,8 @@ new_tbl_format_setup <- function(x, df, width, tbl_sum, body,
extra_cols = extra_cols,
extra_cols_total = extra_cols_total,
max_footer_lines = max_footer_lines,
abbrev_cols = abbrev_cols
abbrev_cols = abbrev_cols,
focus = focus
)

structure(trunc_info, class = "pillar_tbl_format_setup")
Expand Down

0 comments on commit 1329a9e

Please sign in to comment.