Skip to content

Internal class for formatting the data for a column. pillar_shaft() is a coercion method that must be implemented for your data type to display it in a tibble.

This class comes with a default method for print() that calls format(). If print() is called without width argument, the natural width will be used when calling format(). Usually there's no need to implement this method for your subclass.

Your subclass must implement format(), the default implementation just raises an error. Your format() method can assume a valid value for the width argument.

Usage

pillar_shaft(x, ...)

# S3 method for pillar_shaft
print(x, width = NULL, ...)

# S3 method for pillar_shaft
format(x, width, ...)

# S3 method for logical
pillar_shaft(x, ...)

# S3 method for numeric
pillar_shaft(x, ..., sigfig = NULL)

# S3 method for Date
pillar_shaft(x, ...)

# S3 method for POSIXt
pillar_shaft(x, ...)

# S3 method for character
pillar_shaft(x, ..., min_width = NULL)

# S3 method for glue
pillar_shaft(x, ..., min_width = NULL, na_indent = 0L, shorten = NULL)

# S3 method for list
pillar_shaft(x, ...)

# S3 method for factor
pillar_shaft(x, ...)

# S3 method for AsIs
pillar_shaft(x, ...)

# S3 method for default
pillar_shaft(x, ...)

Arguments

x

A vector to format

...

Arguments passed to methods.

width

Width for printing and formatting.

sigfig

Deprecated, use num() or set_num_opts() on the data instead.

min_width

Deprecated, use char() or set_char_opts() on the data instead.

na_indent

Indentation of NA values.

shorten

How to abbreviate the data if necessary:

  • "back" (default): add an ellipsis at the end

  • "front": add an ellipsis at the front

  • "mid": add an ellipsis in the middle

  • "abbreviate": use abbreviate()

Details

The default method will currently format via format(), but you should not rely on this behavior.

Examples

pillar_shaft(1:3)
#> <pillar_ornament>
#> 1
#> 2
#> 3
pillar_shaft(1.5:3.5)
#> <pillar_ornament>
#> 1.5
#> 2.5
#> 3.5
pillar_shaft(NA)
#> <pillar_ornament>
#> NA   
pillar_shaft(c(1:3, NA))
#> <pillar_ornament>
#>  1
#>  2
#>  3
#> NA