pillar provides tools for styling columns of data, artfully using colour and unicode characters to guide the eye.
pillar is not designed for end-users but will eventually be incorporated in packages like tibble.
If you render this in a console that supports colour, you’ll see something that looks like this:
The primary user of this package is tibble, which in the current development version already lets pillar do all the formatting work. Packages that implement a data type to be used in a tibble column can add color with only a few changes:
pillar_shaft()method for your data type.
Suggestsand implement dynamic method registration
Imports, and import the methods you override with a regular
tidyverse/hms#43 shows the changes that were necessary to add colored output for the hms package:
pillar.Rfor the actual implementation (old name
DESCRIPTIONfor the dependency
zzz.Rfor the dynamic method registration
Some more detail is given below.
This method accepts a vector of arbitrary length and is expected to return an S3 object with the following properties:
"min_width", if missing,
format(x, width, ...)that can be called with any value between
characterand has attributes
"align"(with supported values
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
pillar_shaft.numeric() for a code that allows changing the display depending on the available width.
If you avoid the strong dependency on pillar, you need a helper,
register_s3_method(), which you can borrow e.g. from hms. In
.onLoad(), call this helper as follows:
"your_class_name" with the name of the S3 class of your data type.
The earliest use of unicode characters to generate sparklines appears to be from 2009.
Exercising these ideas to their fullest requires a font with good support for block drawing characters. PragamataPro is one such font.