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

formatting

Printing tibbles


Description

One of the main features of the tbl_df class is the printing:

  • Tibbles only print as many rows and columns as fit on one screen, supplemented by a summary of the remaining rows and columns.

  • Tibble reveals the type of each column, which keeps the user informed about whether a variable is, e.g., <chr> or <fct> (character versus factor).

Printing can be tweaked for a one-off call by calling print() explicitly and setting arguments like n and width. More persistent control is available by setting the options described below. See also vignette("digits", package = "pillar") for a comparison to base options, and num() and char() for creating columns with custom formatting options.

As of tibble 3.1.0, printing is handled entirely by the pillar package. If you implement a package that extend tibble, the printed output can be customized in various ways. See vignette("extending", package = "pillar") for details.

Usage

## S3 method for class 'tbl_df'
print(x, ..., n = NULL, width = NULL, n_extra = NULL)

## S3 method for class 'tbl_df'
format(x, ..., n = NULL, width = NULL, n_extra = NULL)

Arguments

x

Object to format or print.

...

Other arguments passed on to individual methods.

n

Number of rows to show. If NULL, the default, will print all rows if less than option tibble.print_max. Otherwise, will print tibble.print_min rows.

width

Width of text output to generate. This defaults to NULL, which means use getOption("tibble.width") or (if also NULL) getOption("width"); the latter displays only the columns that fit on one screen. You can also set options(tibble.width = Inf) to override this default and always print all columns, this may be slow for very wide tibbles.

n_extra

Number of extra columns to print abbreviated information for, if the width is too small for the entire tibble. If NULL, the default, will print information about at most tibble.max_extra_cols extra columns.

Package options

The following options control printing of tbl and tbl_df objects:

  • tibble.print_max: Row number threshold: Maximum number of rows printed. Set to Inf to always print all rows. Default: 20.

  • tibble.print_min: Number of rows printed if row number threshold is exceeded. Default: 10.

  • tibble.width: Output width. Default: NULL (use width option).

  • tibble.max_extra_cols: Number of extra columns printed in reduced form. Default: 100.

The output uses color and highlighting according to the "cli.num_colors" option. Set it to 1 to suppress colored and highlighted output.

  • pillar.bold: Use bold font, e.g. for column headers? This currently defaults to FALSE, because many terminal fonts have poor support for bold fonts.

  • pillar.subtle: Use subtle style, e.g. for row numbers and data types? Default: TRUE.

  • pillar.subtle_num: Use subtle style for insignificant digits? Default: FALSE, is also affected by the pillar.subtle option.

  • pillar.neg: Highlight negative numbers? Default: TRUE.

  • pillar.sigfig: The number of significant digits that will be printed and highlighted, default: 3. Set the pillar.subtle option to FALSE to turn off highlighting of significant digits.

  • pillar.min_title_chars: The minimum number of characters for the column title, default: 15. Column titles may be truncated up to that width to save horizontal space. Set to Inf to turn off truncation of column titles.

  • pillar.min_chars: The minimum number of characters wide to display character columns, default: 0. Character columns may be truncated up to that width to save horizontal space. Set to Inf to turn off truncation of character columns.

  • pillar.max_dec_width: The maximum allowed width for decimal notation, default 13.

Examples

print(as_tibble(mtcars))
print(as_tibble(mtcars), n = 1)
print(as_tibble(mtcars), n = 3)

print(as_tibble(iris), n = 100)

print(mtcars, width = 10)

mtcars2 <- as_tibble(cbind(mtcars, mtcars), .name_repair = "unique")
print(mtcars2, n = 25, n_extra = 3)


print(nycflights13::flights, n_extra = 2)
print(nycflights13::flights, width = Inf)

tibble

Simple Data Frames

v3.1.1
MIT + file LICENSE
Authors
Kirill Müller [aut, cre], Hadley Wickham [aut], Romain Francois [ctb], Jennifer Bryan [ctb], RStudio [cph]
Initial release

We don't support your browser anymore

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