knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%",
  eval = FALSE
)
options(paint_mask_print = FALSE)
knitr::include_graphics("inst/media/paint.png")

paint

Lifecycle: experimental

An artisanally crafted set of print methods for data.frame family rectangles:

Installation

Get the latest release from my r-universe:

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.

library(spData)
library(paint)
paint(nz)

Replacing print()

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:

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():

library(paint)
unpaint(nz)

For convenience unpaint() it will call print() on .LastValue by default if no argument is provided.

Customising

Supported options:

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:

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(), str(), {emphatic}, and the Rainbow CSV addin for VSCode.



MilesMcBain/paint documentation built on Dec. 5, 2023, 9:11 a.m.