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")
An artisanally crafted set of print methods for data.frame
family rectangles:
data.frame
tbl_df
)sf
)data.table
tbl_ts
)Get the latest release from my r-universe:
install.packages( "paint", repos = c(mm = "https://milesmcbain.r-universe.dev", getOption("repos")))
Call paint()
on any compatible data.frame
. Relevant metadata is printed for each class.
library(spData) library(paint) paint(nz)
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)
.
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.
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
.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.
{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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.