The new_pillar_shaft()
constructor creates objects of the "pillar_shaft"
class.
This is a virtual or abstract class, you must specify the class
argument.
By convention, this should be a string that starts with "pillar_shaft_"
.
See vignette("extending", package = "tibble")
for usage examples.
This method accepts a vector of arbitrary length and is expected to return an S3 object with the following properties:
It has an attribute "width"
It can have an attribute "min_width"
, if missing, "width"
is used
It must implement a method format(x, width, ...)
that can be called with any value between min_width
and width
This method must return an object that inherits from character
and has attributes "align"
(with supported values "left"
, "right"
, and "center"
) and "width"
The function new_pillar_shaft()
returns such an object, and also correctly formats NA
values.
In many cases, the implementation of pillar_shaft.your_class_name()
will format the data as a character vector (using color for emphasis) and simply call new_pillar_shaft()
.
See pillar:::pillar_shaft.numeric
for a code that allows changing the display depending on the available width.
new_pillar_shaft_simple()
provides an implementation of the pillar_shaft
class suitable for output that has a fixed formatting, which will be
truncated with a continuation character (ellipsis or ~
) if it doesn't fit
the available width.
By default, the required width is computed from the natural width of the
formatted
argument.
new_pillar_shaft( x, ..., width = NULL, min_width = width, class = NULL, subclass = NULL ) new_pillar_shaft_simple( formatted, ..., width = NULL, align = "left", min_width = NULL, na = NULL, na_indent = 0L )
x | An object |
---|---|
... | Additional attributes. |
width | The maximum column width. |
min_width | The minimum allowed column width, |
class | The name of the subclass. |
subclass | Deprecated, pass the |
formatted | An object coercible to character. |
align | Alignment of the column. |
na | String to use as |
na_indent | Indentation of |
The formatted
argument may also contain ANSI escapes to change color
or other attributes of the text, see crayon.