Printing of prt objects combines the concise yet informative design of only showing as many columns as the terminal width allows for, introduced by tibble, with the data.table approach of showing both the first and last few rows of a table. Implementation wise, the interface is designed to mimic that of tibble printing as closely as possibly, offering the same function arguments and using the same option settings (and default values) as introduced by tibble.

# S3 method for prt
print(x, ..., n = NULL, width = NULL, max_extra_cols = NULL)

# S3 method for prt
format(x, ..., n = NULL, width = NULL, max_extra_cols = NULL)

format_dt(
  x,
  ...,
  n = NULL,
  width = NULL,
  max_extra_cols = NULL,
  max_footer_lines = NULL
)

trunc_dt(...)

Arguments

x

Object to format or print.

...

Passed on to tbl_format_setup().

n

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

width

Width of text output to generate. This defaults to NULL, which means use the width option.

max_extra_cols

Number of extra columns to print abbreviated information for, if the width is too small for the entire tibble. If NULL, the max_extra_cols option is used. The previously defined n_extra argument is soft-deprecated.

max_footer_lines

Maximum number of footer lines. If NULL, the max_footer_lines option is used.

Details

While the function tibble::trunc_mat() does most of the heavy lifting for formatting tibble printing output, prt exports the function trunc_dt(), which drives analogous functionality while adding the top/bottom n row concept. This function can be used for creating print() methods for other classes which represent tabular data, given that this class implements dim(), head() and tail() (and optionally pillar::tbl_sum()) methods. For an example of this, see vignette("prt", package = "prt").

The following session options are set by tibble and are respected by prt, as well as any other package that were to call trunc_dt():

  • 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.

Both tibble and prt rely on pillar for formatting columns and therefore, the following options set by pillar are applicable to prt printing as well.

Options for the pillar package

  • pillar.print_max: Maximum number of rows printed, default: 20. Set to Inf to always print all rows. For compatibility reasons, getOption("tibble.print_max") and getOption("dplyr.print_max") are also consulted, this will be soft-deprecated in pillar v2.0.0.

  • pillar.print_min: Number of rows printed if the table has more than print_max rows, default: 10. For compatibility reasons, getOption("tibble.print_min") and getOption("dplyr.print_min") are also consulted, this will be soft-deprecated in pillar v2.0.0.

  • pillar.width: Output width. Default: NULL (use getOption("width")). This can be larger than getOption("width"), in this case the output of the table's body is distributed over multiple tiers for wide tibbles. For compatibility reasons, getOption("tibble.width") and getOption("dplyr.width") are also consulted, this will be soft-deprecated in pillar v2.0.0.

  • pillar.max_footer_lines: The maximum number of lines in the footer, default: 7. Set to Inf to turn off truncation of footer lines. The max_extra_cols option still limits the number of columns printed.

  • pillar.max_extra_cols: The maximum number of columns printed in the footer, default: 100. Set to Inf to show all columns. Set the more predictable max_footer_lines to control the number of footer lines instead.

  • 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 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 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: 20. 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: 3. 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.

  • pillar.bidi: Set to TRUE for experimental support for bidirectional scripts. Default: FALSE. When this option is set, "left right override" and "first strong isolate" Unicode controls are inserted to ensure that text appears in its intended direction and that the column headings correspond to the correct columns.

  • pillar.superdigit_sep: The string inserted between superscript digits and column names in the footnote. Defaults to a "\u200b", a zero-width space, on UTF-8 platforms, and to ": " on non-UTF-8 platforms.

  • pillar.advice: Should advice be displayed in the footer when columns or rows are missing from the output? Defaults to TRUE for interactive sessions, and to FALSE otherwise.

Examples

cars <- as_prt(mtcars)

print(cars)
#> # A prt:        32 × 11
#> # Partitioning: [32] rows
#>      mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1   21       6 160     110  3.9   2.62  16.5     0     1     4     4
#> 2   21       6 160     110  3.9   2.88  17.0     0     1     4     4
#> 3   22.8     4 108      93  3.85  2.32  18.6     1     1     4     1
#> 4   21.4     6 258     110  3.08  3.22  19.4     1     0     3     1
#> 5   18.7     8 360     175  3.15  3.44  17.0     0     0     3     2
#> 
#> 28  30.4     4  95.1   113  3.77  1.51  16.9     1     1     5     2
#> 29  15.8     8 351     264  4.22  3.17  14.5     0     1     5     4
#> 30  19.7     6 145     175  3.62  2.77  15.5     0     1     5     6
#> 31  15       8 301     335  3.54  3.57  14.6     0     1     5     8
#> 32  21.4     4 121     109  4.11  2.78  18.6     1     1     4     2
#> # ℹ 27 more rows
print(cars, n = 2)
#> # A prt:        32 × 11
#> # Partitioning: [32] rows
#>      mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1   21       6   160   110  3.9   2.62  16.5     0     1     4     4
#> 2   21       6   160   110  3.9   2.88  17.0     0     1     4     4
#> 
#> 31  15       8   301   335  3.54  3.57  14.6     0     1     5     8
#> 32  21.4     4   121   109  4.11  2.78  18.6     1     1     4     2
#> # ℹ 30 more rows
print(cars, width = 30)
#> # A prt:        32 × 11
#> # Partitioning: [32] rows
#>      mpg   cyl  disp    hp
#>    <dbl> <dbl> <dbl> <dbl>
#> 1   21       6 160     110
#> 2   21       6 160     110
#> 3   22.8     4 108      93
#> 4   21.4     6 258     110
#> 5   18.7     8 360     175
#> 
#> 28  30.4     4  95.1   113
#> 29  15.8     8 351     264
#> 30  19.7     6 145     175
#> 31  15       8 301     335
#> 32  21.4     4 121     109
#> # ℹ 27 more rows
#> # ℹ 7 more variables:
#> #   drat <dbl>, wt <dbl>,
#> #   qsec <dbl>, vs <dbl>,
#> #   am <dbl>, gear <dbl>,
#> #   carb <dbl>
print(cars, width = 30, max_extra_cols = 2)
#> # A prt:        32 × 11
#> # Partitioning: [32] rows
#>      mpg   cyl  disp    hp
#>    <dbl> <dbl> <dbl> <dbl>
#> 1   21       6 160     110
#> 2   21       6 160     110
#> 3   22.8     4 108      93
#> 4   21.4     6 258     110
#> 5   18.7     8 360     175
#> 
#> 28  30.4     4  95.1   113
#> 29  15.8     8 351     264
#> 30  19.7     6 145     175
#> 31  15       8 301     335
#> 32  21.4     4 121     109
#> # ℹ 27 more rows
#> # ℹ 7 more variables:
#> #   drat <dbl>, wt <dbl>, …