-
Notifications
You must be signed in to change notification settings - Fork 6
/
README.Rmd
142 lines (106 loc) · 4.32 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
131
132
133
134
135
136
137
138
139
140
141
142
---
output: github_document
---
<!-- README.md is 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%",
eval = FALSE
)
options(paint_mask_print = FALSE)
```
```{r, eval = TRUE, echo = FALSE}
knitr::include_graphics("inst/media/paint.png")
```
# paint
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->
An artisanally crafted set of print methods for `data.frame` family rectangles:
* `data.frame`
* tibble (`tbl_df`)
* simple features geometry collection (`sf`)
* `data.table`
* tsibble (`tbl_ts`)
## Installation
Get the latest release from my [r-universe](https://milesmcbain.r-universe.dev/ui#builds):
```r
install.packages(
"paint",
repos = c(mm = "https://milesmcbain.r-universe.dev", getOption("repos")))
```
## Usage
### paint()
Call `paint()` on any compatible `data.frame`. Relevant metadata is printed for each class.
```{r, eval = TRUE}
library(spData)
library(paint)
paint(nz)
```
### Replacing `print()`
```{r, eval = TRUE, echo = FALSE}
detach(name = "package:paint", unload = TRUE, force = TRUE, character.only = TRUE)
```
You can choose replace the `print()` methods with `paint()` to paint
datafames any time they are output:
```{r, eval = TRUE}
paint::mask_print()
library(tibble)
library(sf)
library(spData)
coffee_data
```
`paint::mask_print()` can be placed in the `.Rprofile` so `paint()` is always preferred.
`unmask_print()` will return the `print()` methods to their defaults for the current session.
By default a reminder message is posted when S3 methods are masked. Disable this
with `options(paint_remind_mask_print = FALSE)`.
### unpaint()
While using `paint()` as your default `print()`, you can call the
original `print()` method with `unpaint()`:
```{r, eval = TRUE}
library(paint)
unpaint(nz)
```
For convenience `unpaint()` it will call `print()` on `.LastValue` by default if no argument is provided.
### Customising
Supported options:
* `paint_palette` the palette to paint row colours with, defaults to
`rainbow_6()`, 6 standard ANSI colours that are supported in most terminals.
* `paint_n_rows` the number of rows to print for each column. Defaults to the
number of colours in the `paint_palette`, but can be set higher for repeating sequences.
* `paint_max_width` the maximum width of the output. 60 is the default. `{paint}` does not resize
based on terminal width by design.
* `paint_align_row_head = c("left", "center", "right")`. How to align the column
title and type. Defaults to `"left"`.
* `paint_dark_mode` darken the `paint_palette` using `crayon::blurred` - not
supported in all terminals.
* `paint_remind_mask_print` show a reminder message when `print()` methods are
manipulated by `{paint}`? defaults to `TRUE`.
### Making a custom palette
There are a number of built in palettes - see ?paintpals. Creating your own
palettes is matter of creating a list of `{crayon}` styles. These can be created
from hex colour codes e.g. `#8DD3C7`. A bit easier than it sounds it practice:
```{r, eval = TRUE}
library(viridisLite)
library(crayon)
my_magma <- lapply(viridisLite::magma(6), crayon::make_style)
options(paint_palette = my_magma)
paint(mtcars)
```
Colours are applied to rows in the order they appear in the palette. You can
also use more advanced `{crayon}` styles, but that is beyond the scope of this
document.
## Design
`{paint}` is a response to my frustrations with standard print methods on wide
rectangles with long naming schemes. It tries to be less noisy, harnessing the
eyes' ability to see colour patterns to reduce markup characters. Only the most
important information for data wrangling is highlighted, the pinnacle being the
column names, which always appear down the left and are never
truncated.
Important issues with the data, e.g. sticky `dplyr` groups, or missing values,
are highlighted to draw extra attention.
`{paint}` draws inspiration from [`glimpse()`](https://github.com/r-lib/pillar/blob/master/R/glimpse.R), `str()`, [`{emphatic}`](https://github.com/coolbutuseless/emphatic), and the
[Rainbow CSV](https://github.com/mechatroner/vscode_rainbow_csv) addin for VSCode.