-
Notifications
You must be signed in to change notification settings - Fork 37
/
README.Rmd
130 lines (89 loc) · 3.53 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
output:
github_document:
html_preview: false
---
<!-- README.md and index.md are generated from README.Rmd. Please edit that file. -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
pkgload::load_all()
set.seed(20230702)
clean_output <- function(x, options) {
x <- gsub("0x[0-9a-f]+", "0xdeadbeef", x)
x <- gsub("dataframe_[0-9]*_[0-9]*", " dataframe_42_42 ", x)
x <- gsub("[0-9]*\\.___row_number ASC", "42.___row_number ASC", x)
index <- x
index <- gsub("─", "-", index)
index <- strsplit(paste(index, collapse = "\n"), "\n---\n")[[1]][[2]]
writeLines(index, "index.md")
x <- fansi::strip_sgr(x)
x
}
options(
cli.num_colors = 256,
cli.width = 80,
width = 80,
pillar.bold = TRUE
)
local({
hook_source <- knitr::knit_hooks$get("document")
knitr::knit_hooks$set(document = clean_output)
})
```
# pillar
<!-- badges: start -->
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![R build status](https://github.com/r-lib/pillar/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/pillar/actions)
[![Coverage status](https://codecov.io/gh/r-lib/pillar/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/pillar)
[![CRAN status](https://www.r-pkg.org/badges/version/pillar)](https://cran.r-project.org/package=pillar)
<!-- badges: end -->
pillar provides tools for styling columns of data, artfully using colour and unicode characters to guide the eye.
## Installation
```{r, eval = FALSE}
# pillar is installed if you install the tidyverse package:
install.packages("tidyverse")
# Alternatively, install just pillar:
install.packages("pillar")
```
## Usage
pillar is a developer-facing package that is not designed for end-users.
It powers the `print()` and `format()` methods for [tibble](https://tibble.tidyverse.org/)s.
It also and defines generics and helpers that are useful for package authors who create custom vector classes (see https://github.com/krlmlr/awesome-vctrs#readme for examples) or custom table classes (like [dbplyr](https://dbplyr.tidyverse.org/) or [sf](https://r-spatial.github.io/sf/)).
```{r}
library(pillar)
x <- 123456789 * (10^c(-3, -5, NA, -8, -10))
pillar(x)
tbl_format_setup(tibble::tibble(x))
```
## Custom vector classes
The primary user of this package is [tibble](https://github.com/tidyverse/tibble), which lets pillar do all the formatting work.
Packages that implement a data type to be used in a tibble column can customize the display by implementing a `pillar_shaft()` method.
```{r}
library(pillar)
percent <- vctrs::new_vctr(9:11 * 0.01, class = "percent")
pillar_shaft.percent <- function(x, ...) {
fmt <- format(vctrs::vec_data(x) * 100)
new_pillar_shaft_simple(paste0(fmt, " ", style_subtle("%")), align = "right")
}
pillar(percent)
```
See `vignette("pillar", package = "vctrs")` for details.
## Custom table classes
pillar provides various extension points for customizing how a tibble-like class is printed.
```{r}
tbl <- vctrs::new_data_frame(list(a = 1:3), class = c("my_tbl", "tbl"))
tbl_sum.my_tbl <- function(x, ...) {
c("Hello" = "world!")
}
tbl
```
See `vignette("extending", package = "pillar")` for a walkthrough of the options.
---
## Code of Conduct
Please note that the pillar project is released with a [Contributor Code of Conduct](https://pillar.r-lib.org/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.