| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/ctl_new_pillar.R |
| 3 |
\name{ctl_new_pillar} |
| 4 |
\alias{ctl_new_pillar} |
| 5 |
\alias{ctl_new_rowid_pillar} |
| 6 |
\title{Customize the appearance of simple pillars in your tibble subclass} |
| 7 |
\usage{ |
| 8 |
ctl_new_pillar(controller, x, width, ..., title = NULL) |
| 9 |
|
| 10 |
ctl_new_rowid_pillar(controller, x, width, ..., title = NULL, type = NULL) |
| 11 |
} |
| 12 |
\arguments{ |
| 13 |
\item{controller}{The object of class \code{"tbl"} currently printed.} |
| 14 |
|
| 15 |
\item{x}{A simple (one-dimensional) vector.} |
| 16 |
|
| 17 |
\item{width}{The available width, can be a vector for multiple tiers.} |
| 18 |
|
| 19 |
\item{...}{These dots are for future extensions and must be empty.} |
| 20 |
|
| 21 |
\item{title}{The title, derived from the name of the column in the data.} |
| 22 |
|
| 23 |
\item{type}{String for specifying a row ID type. Current values in use are |
| 24 |
\code{NULL} and \code{"*"}.} |
| 25 |
} |
| 26 |
\description{ |
| 27 |
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} |
| 28 |
|
| 29 |
Gain full control over the appearance of the pillars of your tibble subclass |
| 30 |
in its body. |
| 31 |
This method is intended for implementers of subclasses of the \code{"tbl"} class. |
| 32 |
Users will rarely need them. |
| 33 |
} |
| 34 |
\details{ |
| 35 |
\code{ctl_new_pillar()} is called to construct pillars for regular (one-dimensional) |
| 36 |
vectors. |
| 37 |
The default implementation returns an object constructed with \code{\link[=pillar]{pillar()}}. |
| 38 |
Extend this method to modify the pillar components returned from the default |
| 39 |
implementation. |
| 40 |
Override this method to completely change the appearance of the pillars. |
| 41 |
Components are created with \code{\link[=new_pillar_component]{new_pillar_component()}} or \code{\link[=pillar_component]{pillar_component()}}. |
| 42 |
In order to customize printing of row IDs, a method can be supplied for the |
| 43 |
\code{ctl_new_rowid_pillar()} generic. |
| 44 |
|
| 45 |
All components must be of the same height. |
| 46 |
This restriction may be levied in the future. |
| 47 |
|
| 48 |
Implementations should return \code{NULL} if none of the data |
| 49 |
fits the available width. |
| 50 |
} |
| 51 |
\examples{ |
| 52 |
\dontshow{if (rlang::is_installed(c("palmerpenguins", "tibble"))) withAutoprint(\{ # examplesIf} |
| 53 |
# Create pillar objects |
| 54 |
ctl_new_pillar( |
| 55 |
palmerpenguins::penguins, |
| 56 |
palmerpenguins::penguins$species[1:3], |
| 57 |
width = 60 |
| 58 |
) |
| 59 |
|
| 60 |
ctl_new_pillar( |
| 61 |
palmerpenguins::penguins, |
| 62 |
palmerpenguins::penguins$bill_length_mm[1:3], |
| 63 |
width = 60 |
| 64 |
) |
| 65 |
\dontshow{\}) # examplesIf} |
| 66 |
|
| 67 |
# Customize output |
| 68 |
lines <- function(char = "-") { |
| 69 |
stopifnot(nchar(char) == 1) |
| 70 |
structure(char, class = "lines") |
| 71 |
} |
| 72 |
|
| 73 |
format.lines <- function(x, width, ...) { |
| 74 |
paste(rep(x, width), collapse = "") |
| 75 |
} |
| 76 |
|
| 77 |
ctl_new_pillar.line_tbl <- function(controller, x, width, ...) { |
| 78 |
out <- NextMethod() |
| 79 |
new_pillar(list( |
| 80 |
title = out$title, |
| 81 |
type = out$type, |
| 82 |
lines = new_pillar_component(list(lines("=")), width = 1), |
| 83 |
data = out$data |
| 84 |
)) |
| 85 |
} |
| 86 |
|
| 87 |
ctl_new_rowid_pillar.line_tbl <- function(controller, x, width, ...) { |
| 88 |
out <- NextMethod() |
| 89 |
new_pillar( |
| 90 |
list( |
| 91 |
title = out$title, |
| 92 |
type = out$type, |
| 93 |
lines = new_pillar_component(list(lines("=")), width = 1), |
| 94 |
data = out$data |
| 95 |
), |
| 96 |
width = as.integer(floor(log10(max(nrow(x), 1))) + 1) |
| 97 |
) |
| 98 |
} |
| 99 |
|
| 100 |
vctrs::new_data_frame( |
| 101 |
list(a = 1:3, b = letters[1:3]), |
| 102 |
class = c("line_tbl", "tbl") |
| 103 |
) |
| 104 |
|
| 105 |
ctl_new_rowid_pillar.roman_tbl <- function(controller, x, width, ...) { |
| 106 |
out <- NextMethod() |
| 107 |
rowid <- utils::as.roman(seq_len(nrow(x))) |
| 108 |
width <- max(nchar(as.character(rowid))) |
| 109 |
new_pillar( |
| 110 |
list( |
| 111 |
title = out$title, |
| 112 |
type = out$type, |
| 113 |
data = pillar_component( |
| 114 |
new_pillar_shaft(list(row_ids = rowid), |
| 115 |
width = width, |
| 116 |
class = "pillar_rif_shaft" |
| 117 |
) |
| 118 |
) |
| 119 |
), |
| 120 |
width = width |
| 121 |
) |
| 122 |
} |
| 123 |
|
| 124 |
vctrs::new_data_frame( |
| 125 |
list(a = 1:3, b = letters[1:3]), |
| 126 |
class = c("roman_tbl", "tbl") |
| 127 |
) |
| 128 |
|
| 129 |
} |
| 130 |
\seealso{ |
| 131 |
See \code{\link[=ctl_new_pillar_list]{ctl_new_pillar_list()}} for creating pillar objects for compound columns: |
| 132 |
packed data frames, matrices, or arrays. |
| 133 |
} |