Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

tbl_format_setup

Set up formatting


Description

tbl_format_setup() is called by format.tbl(). This method collects information that is common to the header, body, and footer parts of a tibble. Examples:

  • the dimensions sometimes are reported both in the header and (implicitly) in the footer of a tibble;

  • the columns shown in the body decide which columns are shown in the footer.

This information is computed once in tbl_format_setup(). The result is passed on to the tbl_format_header(), tbl_format_body(), and tbl_format_footer() methods. If you need to customize parts of the printed output independently, override these methods instead.

Usage

tbl_format_setup(x, width = NULL, ..., n = NULL, max_extra_cols = NULL)

## S3 method for class 'tbl'
tbl_format_setup(x, width, ..., n, max_extra_cols)

Arguments

x

An object.

width

Actual width for printing, a numeric greater than zero. This argument is mandatory for all implementations of this method.

...

Extra arguments to print.tbl() or format.tbl().

n

Actual number of rows to print. No options should be considered by implementations of this method.

max_extra_cols

Number of columns to print abbreviated information for, if the width is too small for the entire tibble. No options should be considered by implementations of this method.

Details

Extend this method to prepare information that is used in several parts of the printed output of a tibble-like object, or to collect additional arguments passed via ... to print.tbl() or format.tbl().

We expect that tbl_format_setup() is extended only rarely, and overridden only in exceptional circumstances, if at all. If you override this method, you must also implement tbl_format_header(), tbl_format_body(), and tbl_format_footer() for your class.

Implementing a method allows to override printing and formatting of the entire object without overriding the print() and format() methods directly. This allows to keep the logic of the width and n arguments.

The default method for the "tbl" class collects information for standard printing for tibbles. See new_tbl_format_setup() for details on the returned object.

Value

An object that can be passed as setup argument to tbl_format_header(), tbl_format_body(), and tbl_format_footer().

Examples

tbl_format_setup(palmerpenguins::penguins)

pillar

Coloured Formatting for Columns

v1.6.0
MIT + file LICENSE
Authors
Kirill Müller [aut, cre], Hadley Wickham [aut], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.