Gain full control over the appearance of the pillars of your tibble subclass in its body. These methods are intended for implementers of subclasses of the "tbl" class. Users will rarely need them.

ctl_new_pillar(controller, x, width, ..., title = NULL)

ctl_new_compound_pillar(controller, x, width, ..., title = NULL)

Arguments

controller

The object of class "tbl" currently printed.

x

A vector, can also be a data frame, array or matrix in ctl_new_compound_pillar()

width

The available width, can be a vector for multiple tiers

...

These dots are for future extensions and must be empty.

title

The title, derived from the name of the column in the data

Details

ctl_new_pillar() is called to construct pillars for regular (one-dimensional) vectors. The default implementation returns an object constructed with pillar(). Extend this method to tweak pillar components returned from the default implementation. Override this method to completely change the appearance of the pillars.

ctl_new_compound_pillar() is called for compound pillars: columns that are data frames, matrices or arrays. The default implementation returns a compound pillar with suitable formatting for the titles and types of the sub-pillar. Users will only rarely need to override this method if ever.

All components must be of the same height. This restriction may be levied in the future.

Implementations should return NULL if none of the data fits the available width.

Examples

# Create pillar objects
ctl_new_pillar(
  palmerpenguins::penguins,
  palmerpenguins::penguins$species[1:3], width = 60
)
#> <pillar>
#> <fct>                                                       
#> Adelie                                                      
#> Adelie                                                      
#> Adelie                                                      
ctl_new_pillar(
  palmerpenguins::penguins,
  palmerpenguins::penguins$bill_length_mm[1:3],
  width = 60
)
#> <pillar>
#>                                                        <dbl>
#>                                                         39.1
#>                                                         39.5
#>                                                         40.3

# Packed data frame
ctl_new_compound_pillar(
  tibble::tibble(),
  palmerpenguins::penguins,
  width = 60
)
#> <compound_pillar[5]>
#> species                                                   
#> <fct>                                                     
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Adelie                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Gentoo                                                    
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> Chinstrap                                                 
#> … and 4 more sub-pillars

# Packed matrix
ctl_new_compound_pillar(tibble::tibble(), matrix(1:6, ncol = 2), width = 60)
#> <compound_pillar[2]>
#>      [,1]
#>     <int>
#>         1
#>         2
#>         3
#> … and 1 more sub-pillars

# Packed array
ctl_new_compound_pillar(tibble::tibble(), Titanic, width = 60)
#> <pillar>
#>                                              <table[,2,2,2]>
#>                                                          0 …
#>                                                          0 …
#>                                                         35 …
#>                                                          0 …

# Customize output
lines <- function(char = "-") {
  stopifnot(nchar(char) == 1)
  structure(char, class = "lines")
}

format.lines <- function(x, width, ...) {
  paste(rep(x, width), collapse = "")
}

ctl_new_pillar.line_tbl <- function(controller, x, width, ..., title = NULL) {
  out <- NextMethod()
  new_pillar(list(
    title = out$title,
    type = out$type,
    lines = new_pillar_component(list(lines("=")), width = 1),
    data = out$data
  ))
}

vctrs::new_data_frame(
  list(a = 1:3, b = letters[1:3]),
  class = c("line_tbl", "tbl")
)
#> # A data frame: 3 × 2
#>       a b    
#>   <int> <chr>
#> 1     1 a    
#> 2     2 b    
#> 3     3 c