Debian Codegraph @

man/tbl_format_setup.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/tbl-format-setup.R
3 \name{tbl_format_setup}
4 \alias{tbl_format_setup}
5 \alias{tbl_format_setup.tbl}
6 \title{Set up formatting}
7 \usage{
8 tbl_format_setup(
9 x,
10 width = NULL,
11 ...,
12 setup = list(tbl_sum = tbl_sum(x)),
13 n = NULL,
14 max_extra_cols = NULL,
15 max_footer_lines = NULL,
16 focus = NULL
17 )
18
19 \method{tbl_format_setup}{tbl}(
20 x,
21 width,
22 ...,
23 setup,
24 n,
25 max_extra_cols,
26 max_footer_lines,
27 focus
28 )
29 }
30 \arguments{
31 \item{x}{An object.}
32
33 \item{width}{Actual width for printing, a numeric greater than zero.
34 This argument is mandatory for all implementations of this method.}
35
36 \item{...}{Extra arguments to \code{\link[=print.tbl]{print.tbl()}} or \code{\link[=format.tbl]{format.tbl()}}.}
37
38 \item{setup}{This generic is first called with \code{setup = NULL} .
39 If the method \emph{evaluates} this argument, the return value
40 will only be used in a call to \code{\link[=tbl_format_header]{tbl_format_header()}},
41 and after that, a second call to this generic will be made
42 with the return value of the first call as \code{setup}
43 which then will be used in calls to \code{\link[=tbl_format_body]{tbl_format_body()}} and \code{\link[=tbl_format_footer]{tbl_format_footer()}}.
44 This allows displaying the header before starting the computation
45 required for the body and footer.}
46
47 \item{n}{Actual number of rows to print.
48 No \link[=pillar_options]{options} should be considered
49 by implementations of this method.}
50
51 \item{max_extra_cols}{Number of columns to print abbreviated information for,
52 if the width is too small for the entire tibble.
53 No \link[=pillar_options]{options} should be considered
54 by implementations of this method.}
55
56 \item{max_footer_lines}{Maximum number of lines for the footer.
57 No \link[=pillar_options]{options} should be considered
58 by implementations of this method.}
59
60 \item{focus}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
61
62 Names of columns to show preferentially if space is tight.}
63 }
64 \value{
65 An object that can be passed as \code{setup} argument to
66 \code{\link[=tbl_format_header]{tbl_format_header()}}, \code{\link[=tbl_format_body]{tbl_format_body()}}, and \code{\link[=tbl_format_footer]{tbl_format_footer()}}.
67 }
68 \description{
69 \code{tbl_format_setup()} is called by \code{\link[=format.tbl]{format.tbl()}}.
70 This method collects information that is common to the header, body,
71 and footer parts of a tibble.
72 Examples:
73 \itemize{
74 \item the dimensions sometimes are reported both in the header
75 and (implicitly) in the footer of a tibble;
76 \item the columns shown in the body decide which columns are shown in the footer.
77 }
78
79 This information is computed in \code{tbl_format_setup()}.
80 The result is passed on to the
81 \code{\link[=tbl_format_header]{tbl_format_header()}}, \code{\link[=tbl_format_body]{tbl_format_body()}}, and \code{\link[=tbl_format_footer]{tbl_format_footer()}}
82 methods.
83 If you need to customize parts of the printed output independently,
84 override these methods instead.
85
86 By checking the \code{setup} argument, you can return an object that is
87 suitable for a call to \code{\link[=tbl_format_header]{tbl_format_header()}} if \code{setup} is \code{NULL}.
88 In this case, the method is called a second time with the return value
89 of the first call as \code{setup}.
90 }
91 \details{
92 Extend this method to prepare information that is used
93 in several parts of the printed output of a tibble-like object,
94 or to collect additional arguments passed via \code{...} to
95 \code{\link[=print.tbl]{print.tbl()}} or \code{\link[=format.tbl]{format.tbl()}}.
96
97 We expect that \code{tbl_format_setup()} is extended only rarely,
98 and overridden only in exceptional circumstances, if at all.
99 If you override this method, you must also implement
100 \code{\link[=tbl_format_header]{tbl_format_header()}}, \code{\link[=tbl_format_body]{tbl_format_body()}}, and \code{\link[=tbl_format_footer]{tbl_format_footer()}}
101 for your class.
102
103 Implementing a method
104 allows to override printing and formatting of the entire object
105 without overriding the \code{\link[=print]{print()}} and \code{\link[=format]{format()}} methods directly.
106 This allows to keep the logic of the \code{width} and \code{n} arguments.
107
108 The default method for the \code{"tbl"} class collects information for
109 standard printing for tibbles.
110 See \code{\link[=new_tbl_format_setup]{new_tbl_format_setup()}} for details on the returned object.
111 }
112 \examples{
113 \dontshow{if (rlang::is_installed(c("palmerpenguins", "tibble"))) withAutoprint(\{ # examplesIf}
114 tbl_format_setup(palmerpenguins::penguins)
115 \dontshow{\}) # examplesIf}
116 }