| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/shaft-.R, R/shaft-simple.R |
| 3 |
\name{new_pillar_shaft} |
| 4 |
\alias{new_pillar_shaft} |
| 5 |
\alias{new_pillar_shaft_simple} |
| 6 |
\title{Constructor for column data} |
| 7 |
\usage{ |
| 8 |
new_pillar_shaft( |
| 9 |
x, |
| 10 |
..., |
| 11 |
width = NULL, |
| 12 |
min_width = width, |
| 13 |
type_sum = NULL, |
| 14 |
class = NULL, |
| 15 |
subclass = NULL |
| 16 |
) |
| 17 |
|
| 18 |
new_pillar_shaft_simple( |
| 19 |
formatted, |
| 20 |
..., |
| 21 |
width = NULL, |
| 22 |
align = "left", |
| 23 |
min_width = NULL, |
| 24 |
na = NULL, |
| 25 |
na_indent = 0L, |
| 26 |
shorten = c("back", "front", "mid", "abbreviate"), |
| 27 |
short_formatted = NULL |
| 28 |
) |
| 29 |
} |
| 30 |
\arguments{ |
| 31 |
\item{x}{An object} |
| 32 |
|
| 33 |
\item{...}{Passed on to \code{\link[=new_pillar_shaft]{new_pillar_shaft()}}.} |
| 34 |
|
| 35 |
\item{width}{The maximum column width.} |
| 36 |
|
| 37 |
\item{min_width}{The minimum allowed column width, \code{width} if omitted.} |
| 38 |
|
| 39 |
\item{type_sum}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} |
| 40 |
|
| 41 |
Override the type summary displayed at the top of the data. |
| 42 |
This argument, if given, takes precedence over the type summary provided by |
| 43 |
\code{\link[=type_sum]{type_sum()}}.} |
| 44 |
|
| 45 |
\item{class}{The name of the subclass.} |
| 46 |
|
| 47 |
\item{subclass}{Deprecated, pass the \code{class} argument instead.} |
| 48 |
|
| 49 |
\item{formatted}{The data to show, an object coercible to \link{character}.} |
| 50 |
|
| 51 |
\item{align}{Alignment of the column.} |
| 52 |
|
| 53 |
\item{na}{String to use as \code{NA} value, defaults to \code{"NA"} styled with |
| 54 |
\code{\link[=style_na]{style_na()}} with fallback if color is not available.} |
| 55 |
|
| 56 |
\item{na_indent}{Indentation of \code{NA} values.} |
| 57 |
|
| 58 |
\item{shorten}{How to abbreviate the data if necessary: |
| 59 |
\itemize{ |
| 60 |
\item \code{"back"} (default): add an ellipsis at the end |
| 61 |
\item \code{"front"}: add an ellipsis at the front |
| 62 |
\item \code{"mid"}: add an ellipsis in the middle |
| 63 |
\item \code{"abbreviate"}: use \code{\link[=abbreviate]{abbreviate()}} |
| 64 |
}} |
| 65 |
|
| 66 |
\item{short_formatted}{If provided, a character vector of the same length as |
| 67 |
\code{formatted}, to be used when the available width is insufficient to show |
| 68 |
the full output.} |
| 69 |
} |
| 70 |
\description{ |
| 71 |
The \code{new_pillar_shaft()} constructor creates objects of the \code{"pillar_shaft"} |
| 72 |
class. |
| 73 |
This is a virtual or abstract class, you must specify the \code{class} |
| 74 |
argument. |
| 75 |
By convention, this should be a string that starts with \code{"pillar_shaft_"}. |
| 76 |
See \code{vignette("extending", package = "tibble")} for usage examples. |
| 77 |
|
| 78 |
This method accepts a vector of arbitrary length and is expected to return an S3 object with the following properties: |
| 79 |
\itemize{ |
| 80 |
\item It has an attribute \code{"width"} |
| 81 |
\item It can have an attribute \code{"min_width"}, if missing, \code{"width"} is used |
| 82 |
\item It must implement a method \code{format(x, width, ...)} that can be called with any value between \code{min_width} and \code{width} |
| 83 |
\item This method must return an object that inherits from \code{character} and has attributes \code{"align"} (with supported values \code{"left"}, \code{"right"}, and \code{"center"}) and \code{"width"} |
| 84 |
} |
| 85 |
|
| 86 |
The function \code{\link[=new_pillar_shaft]{new_pillar_shaft()}} returns such an object, and also correctly formats \code{NA} values. |
| 87 |
In many cases, the implementation of \code{pillar_shaft.your_class_name()} will format the data as a character vector (using color for emphasis) and simply call \code{new_pillar_shaft()}. |
| 88 |
See \code{pillar:::pillar_shaft.numeric} for a code that allows changing the display depending on the available width. |
| 89 |
|
| 90 |
\code{new_pillar_shaft_simple()} provides an implementation of the \code{pillar_shaft} |
| 91 |
class suitable for output that has a fixed formatting, which will be |
| 92 |
truncated with a continuation character (ellipsis or \code{~}) if it doesn't fit |
| 93 |
the available width. |
| 94 |
By default, the required width is computed from the natural width of the |
| 95 |
\code{formatted} argument. |
| 96 |
} |
| 97 |
\details{ |
| 98 |
The \code{formatted} argument may also contain ANSI escapes to change color |
| 99 |
or other attributes of the text, provided e.g. by the \pkg{cli} package. |
| 100 |
} |