Debian Codegraph @

R/tbl-format-body.R

raw
1 #' Format the body of a tibble
2 #'
3 #' @description
4 #' `r lifecycle::badge("experimental")`
5 #'
6 #' For easier customization, the formatting of a tibble is split
7 #' into three components: header, body, and footer.
8 #' The `tbl_format_body()` method is responsible for formatting the body
9 #' of a tibble.
10 #'
11 #' Override this method if you need to change the appearance of all parts
12 #' of the body.
13 #' If you only need to change the appearance of a single data type,
14 #' override [vctrs::vec_ptype_abbr()] and [pillar_shaft()] for this data type.
15 #'
16 #' @inheritParams rlang::args_dots_empty
17 #' @param x A tibble-like object.
18 #' @param setup A setup object returned from [tbl_format_setup()].
19 #'
20 #' @return
21 #' A character vector.
22 #'
23 #' @export
24 #' @examplesIf rlang::is_installed(c("palmerpenguins", "tibble"))
25 #' setup <- tbl_format_setup(palmerpenguins::penguins)
26 #' tbl_format_body(palmerpenguins::penguins, setup)
27 #'
28 #' # Shortcut for debugging
29 #' tbl_format_body(setup)
30 tbl_format_body <- function(x, setup, ...) {
31 check_dots_empty()
32
33 UseMethod("tbl_format_body")
34 }
35
36 #' @export
37 tbl_format_body.tbl <- function(x, setup, ...) {
38 force(setup)
39 setup$body
40 }
41
42 #' @export
43 tbl_format_body.pillar_tbl_format_setup <- function(x, ...) {
44 as_glue(c(
45 cli::style_bold("<tbl_format_body(setup)>"),
46 tbl_format_body(x$x, setup = x)
47 ))
48 }