An open API service indexing awesome lists of open source software.

https://github.com/MilesMcBain/paint

paint the data
https://github.com/MilesMcBain/paint

Last synced: 4 months ago
JSON representation

paint the data

Awesome Lists containing this project

README

        

---
output: github_document
---

```{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

[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)

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.