diff --git a/R/tbl-format-header.R b/R/tbl-format-header.R index f8ae970bb..745c2d593 100644 --- a/R/tbl-format-header.R +++ b/R/tbl-format-header.R @@ -33,6 +33,10 @@ tbl_format_header <- function(x, setup, ...) { #' @export tbl_format_header.tbl <- function(x, setup, ...) { named_header <- setup$tbl_sum + focus <- attr(x, "pillar_focus") + if (!is.null(focus)) { + named_header <- c(named_header, "Focus columns" = collapse(tick_if_needed(focus))) + } if (all(names2(named_header) == "")) { header <- named_header diff --git a/R/tbl-format.R b/R/tbl-format.R index d0a2d5477..ff147dda6 100644 --- a/R/tbl-format.R +++ b/R/tbl-format.R @@ -67,7 +67,8 @@ format_tbl <- function(x, width = NULL, ..., width = width, ..., n = n, max_extra_cols = max_extra_cols, - max_footer_lines = max_footer_lines + max_footer_lines = max_footer_lines, + focus = attr(x, "pillar_focus") ) header <- tbl_format_header(x, setup) diff --git a/R/tbl.R b/R/tbl.R index 917babdf1..9b257af00 100644 --- a/R/tbl.R +++ b/R/tbl.R @@ -1,6 +1,5 @@ new_tbl <- function(x = list(), n = NULL, ..., class = NULL) { - check_dots_empty() - new_data_frame(x, n, class = c(class, "tbl")) + new_data_frame(x, n, class = c(class, "tbl"), ...) } as_tbl <- function(x, ...) { diff --git a/tests/testthat/_snaps/tbl-format-header.md b/tests/testthat/_snaps/tbl-format-header.md index 0215b4a58..3bc7d1569 100644 --- a/tests/testthat/_snaps/tbl-format-header.md +++ b/tests/testthat/_snaps/tbl-format-header.md @@ -26,4 +26,12 @@ # A data frame: 0 x 0 # foo: bar + Code + # Focus columns + tbl_format_header(tbl_format_setup(new_tbl(trees, pillar_focus = "Volume"), + width = 30)) + Output + + # A data frame: 31 x 3 + # Focus columns: Volume diff --git a/tests/testthat/_snaps/tbl-format.md b/tests/testthat/_snaps/tbl-format.md index 316d7cd93..f4390ed58 100644 --- a/tests/testthat/_snaps/tbl-format.md +++ b/tests/testthat/_snaps/tbl-format.md @@ -256,4 +256,26 @@ 10 19.2 6 168. 123 3.92 3.44 # ... with 22 more rows, and 5 more # variables: qsec , ... + Code + print(tbl_format_setup(new_tbl(trees, pillar_focus = "Volume"), width = 30)) + Output + + + # A data frame: 31 x 3 + # Focus columns: Volume + + Girth Height Volume + + 1 8.3 70 10.3 + 2 8.6 65 10.3 + 3 8.8 63 10.2 + 4 10.5 72 16.4 + 5 10.7 81 18.8 + 6 10.8 83 19.7 + 7 11 66 15.6 + 8 11 75 18.2 + 9 11.1 80 22.6 + 10 11.2 75 19.9 + + # ... with 21 more rows diff --git a/tests/testthat/test-tbl-format-header.R b/tests/testthat/test-tbl-format-header.R index 575357a53..af20b5bcb 100644 --- a/tests/testthat/test-tbl-format-header.R +++ b/tests/testthat/test-tbl-format-header.R @@ -12,5 +12,8 @@ test_that("tbl_format_header() results", { "Custom tbl_sum()" tbl_format_header(tbl_format_setup(new_foo_tbl(), width = 30)) + + "Focus columns" + tbl_format_header(tbl_format_setup(new_tbl(trees, pillar_focus = "Volume"), width = 30)) }) }) diff --git a/tests/testthat/test-tbl-format.R b/tests/testthat/test-tbl-format.R index 8855773d1..528efde50 100644 --- a/tests/testthat/test-tbl-format.R +++ b/tests/testthat/test-tbl-format.R @@ -46,6 +46,8 @@ test_that("print() output", { expect_snapshot({ print(as_tbl(mtcars), width = 40, n_extra = 1) + + print(tbl_format_setup(new_tbl(trees, pillar_focus = "Volume"), width = 30)) }) })