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{ 8new_pillar_shaft( 9 x, 10 ..., 11 width = NULL, 12 min_width = width, 13 class = NULL, 14 subclass = NULL 15) 16 17new_pillar_shaft_simple( 18 formatted, 19 ..., 20 width = NULL, 21 align = "left", 22 min_width = NULL, 23 na = NULL, 24 na_indent = 0L, 25 shorten = c("back", "front", "mid", "abbreviate") 26) 27} 28\arguments{ 29\item{x}{An object} 30 31\item{...}{Additional attributes.} 32 33\item{width}{The maximum column width.} 34 35\item{min_width}{The minimum allowed column width, \code{width} if omitted.} 36 37\item{class}{The name of the subclass.} 38 39\item{subclass}{Deprecated, pass the \code{class} argument instead.} 40 41\item{formatted}{An object coercible to \link{character}.} 42 43\item{align}{Alignment of the column.} 44 45\item{na}{String to use as \code{NA} value, defaults to \code{"NA"} styled with 46\code{\link[=style_na]{style_na()}} with fallback if color is not available.} 47 48\item{na_indent}{Indentation of \code{NA} values.} 49 50\item{shorten}{How to abbreviate the data if necessary: 51\itemize{ 52\item \code{"back"} (default): add an ellipsis at the end 53\item \code{"front"}: add an ellipsis at the front 54\item \code{"mid"}: add an ellipsis in the middle 55\item \code{"abbreviate"}: use \code{\link[=abbreviate]{abbreviate()}} 56}} 57} 58\description{ 59The \code{new_pillar_shaft()} constructor creates objects of the \code{"pillar_shaft"} 60class. 61This is a virtual or abstract class, you must specify the \code{class} 62argument. 63By convention, this should be a string that starts with \code{"pillar_shaft_"}. 64See \code{vignette("extending", package = "tibble")} for usage examples. 65 66This method accepts a vector of arbitrary length and is expected to return an S3 object with the following properties: 67\itemize{ 68\item It has an attribute \code{"width"} 69\item It can have an attribute \code{"min_width"}, if missing, \code{"width"} is used 70\item It must implement a method \code{format(x, width, ...)} that can be called with any value between \code{min_width} and \code{width} 71\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"} 72} 73 74The function \code{\link[=new_pillar_shaft]{new_pillar_shaft()}} returns such an object, and also correctly formats \code{NA} values. 75In 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()}. 76See \code{pillar:::pillar_shaft.numeric} for a code that allows changing the display depending on the available width. 77 78\code{new_pillar_shaft_simple()} provides an implementation of the \code{pillar_shaft} 79class suitable for output that has a fixed formatting, which will be 80truncated with a continuation character (ellipsis or \code{~}) if it doesn't fit 81the available width. 82By default, the required width is computed from the natural width of the 83\code{formatted} argument. 84} 85\details{ 86The \code{formatted} argument may also contain ANSI escapes to change color 87or other attributes of the text, see \link{crayon}. 88} 89