Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pillar

Object for formatting a vector suitable for tabular display


Description

pillar() creates an object that formats a vector. The output uses one row for a title (if given), one row for the type, and vec_size(x) rows for the data.

Usage

pillar(x, title = NULL, width = NULL, ...)

Arguments

x

A vector to format.

title

An optional title for the column. The title will be used "as is", no quoting will be applied.

width

Default width, optional.

...

Passed on to pillar_shaft().

Details

A pillar consists of arbitrary components. The pillar() constructor uses title, type, and data.

All components are formatted via format() when displaying the pillar. A width argument is passed to each format() call.

As of pillar 1.5.0, pillar() returns NULL if the width is insufficient to display the data.

Examples

x <- 123456789 * (10^c(-1, -3, -5, NA, -8, -10))
pillar(x)
pillar(-x)
pillar(runif(10))
pillar(rcauchy(20))

# Special values are highlighted
pillar(c(runif(5), NA, NaN, Inf, -Inf))

# Very wide ranges will be displayed in scientific format
pillar(c(1e10, 1e-10), width = 20)
pillar(c(1e10, 1e-10))

x <- c(FALSE, NA, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE)
pillar(x)

x <- c("This is string is rather long", NA, "?", "Short")
pillar(x)
pillar(x, width = 30)
pillar(x, width = 5)

date <- as.Date("2017-05-15")
pillar(date + c(1, NA, 3:5))
pillar(as.POSIXct(date) + c(30, NA, 600, 3600, 86400))

pillar

Coloured Formatting for Columns

v1.6.0
MIT + file LICENSE
Authors
Kirill Müller [aut, cre], Hadley Wickham [aut], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.