• Stars
    star
    136
  • Rank 258,229 (Top 6 %)
  • Language
    R
  • License
    Other
  • Created almost 3 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

paint the data

paint

Lifecycle: 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:

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)
#> sf [16, 7]
#> active geometry column: geom (MULTIPOLYGON)
#> crs: 2193 (NZGD2000 / New Zealand Transverse Mercator 2000)
#> crs unit: metre
#> Name          chr Northland Auckland Waikato Bay of Plenty ~
#> Island        chr North North North North North North
#> Land_area     dbl 12500.561149 4941.572557 23900.036383 120~
#> Population    dbl 175500 1657200 460100 299900 48500 164000
#> Median_income int 23400 29600 27900 26200 24400 26100
#> Sex_ratio     dbl 0.942453 0.944286 0.95205 0.928039 0.9349~
#> geom          sfc MPOLY 1,784B MPOLY 2,288B MPOLY 2,376B MP~

Replacing print()

You can choose replace the print() methods with paint() to paint datafames any time they are output:

paint::mask_print()
#> {paint} masked print.data.frame
#> {paint} masked print.tbl_df
#> {paint} masked print.sf
library(tibble)
library(sf)
#> Linking to GEOS 3.10.1, GDAL 3.4.0, PROJ 8.2.0; sf_use_s2() is TRUE
library(spData)
coffee_data
#> tibble [47, 3]
#> name_long              chr Angola Bolivia Brazil Burundi Ca~
#> coffee_production_2016 int NA 3 3277 37 8 NA
#> coffee_production_2017 int NA 4 2786 38 6 NA

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)
#> Simple feature collection with 16 features and 6 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 1090144 ymin: 4748537 xmax: 2089533 ymax: 6191874
#> Projected CRS: NZGD2000 / New Zealand Transverse Mercator 2000
#> First 10 features:
#>                 Name Island Land_area Population Median_income Sex_ratio
#> 1          Northland  North 12500.561     175500         23400 0.9424532
#> 2           Auckland  North  4941.573    1657200         29600 0.9442858
#> 3            Waikato  North 23900.036     460100         27900 0.9520500
#> 4      Bay of Plenty  North 12071.145     299900         26200 0.9280391
#> 5           Gisborne  North  8385.827      48500         24400 0.9349734
#> 6        Hawke's Bay  North 14137.524     164000         26100 0.9238375
#> 7           Taranaki  North  7254.480     118000         29100 0.9569363
#> 8  Manawatu-Wanganui  North 22220.608     234500         25000 0.9387734
#> 9         Wellington  North  8048.553     513900         32700 0.9335524
#> 10        West Coast  South 23245.456      32400         26900 1.0139072
#>                              geom
#> 1  MULTIPOLYGON (((1745493 600...
#> 2  MULTIPOLYGON (((1803822 590...
#> 3  MULTIPOLYGON (((1860345 585...
#> 4  MULTIPOLYGON (((2049387 583...
#> 5  MULTIPOLYGON (((2024489 567...
#> 6  MULTIPOLYGON (((2024489 567...
#> 7  MULTIPOLYGON (((1740438 571...
#> 8  MULTIPOLYGON (((1866732 566...
#> 9  MULTIPOLYGON (((1881590 548...
#> 10 MULTIPOLYGON (((1557042 531...

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:

library(viridisLite)
library(crayon)
my_magma <- lapply(viridisLite::magma(6), crayon::make_style)
options(paint_palette = my_magma)
paint(mtcars)
#> data.frame [32, 11]
#> mpg  dbl 21 21 22.8 21.4 18.7 18.1
#> cyl  dbl 6 6 4 6 8 6
#> disp dbl 160 160 108 258 360 225
#> hp   dbl 110 110 93 110 175 105
#> drat dbl 3.9 3.9 3.85 3.08 3.15 2.76
#> wt   dbl 2.62 2.875 2.32 3.215 3.44 3.46
#> qsec dbl 16.46 17.02 18.61 19.44 17.02 20.22
#> vs   dbl 0 0 1 1 0 1
#> am   dbl 1 1 1 0 0 0
#> gear dbl 4 4 4 3 3 3
#> carb dbl 4 4 1 1 2 1

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.

More Repositories

1

datapasta

On top of spaghetti, all covered in cheese....
R
874
star
2

breakerofchains

Break your chain at the cursor line. Run the first bit. See the output. Be free.
R
149
star
3

gistfo

Turn your RStudio untitled tabs into gists. You monsters.
R
140
star
4

capsule

An inversion of renv for low effort reproducible R package libraries
R
140
star
5

friendlyeval

A friendly interface to tidyeval/rlang that will excuse itself when you're done.
R
107
star
6

fnmate

A function definition generator.
R
94
star
7

tflow

An opinionated lightweight template for smooth targets flows.
R
83
star
8

dflow

Automatically setup a drake project
R
80
star
9

markdrive

Edit Google docs in Markdown with a little help from #rstats
R
71
star
10

slippymath

R functions for dealing with slippy map tile servers.
R
65
star
11

esscss

This repository collects links to ESS configurations shared by #rstats community members.
57
star
12

packup

Collect, stow, and alphabetise library() calls in your R files.
R
57
star
13

deplearning

Detect, install and update R source dependencies.
R
52
star
14

rmdgh

Put Github in your Rmd and Rmd in your GitHub
R
52
star
15

vsconfig

My config for R in VSCode
R
47
star
16

inlegend

Styling for inset ggplot2 map legends
R
41
star
17

nycr_meetup_talk

That Feeling of Workflowing
39
star
18

wisegroup

Now I am become death, destroyer of groups....
R
39
star
19

portal

move data between R processes
R
35
star
20

git_4_sci

A 3.5 hour introduction to basic shell and git/GitHub workflow for ACMES researchers.
CSS
28
star
21

really_useful_engines

R
23
star
22

rmdocs

browse help files as Rmarkdown documents
R
19
star
23

mufflr

Experimental RStudio addins for pipe and assign.
R
19
star
24

mvtview

a Mapbox vector tile server and viewer for R
R
15
star
25

flippingtables

turn the tables on data.frame printing
R
14
star
26

mmmisc

My Library of R Helpers
R
14
star
27

rstudioconf_talk

my rstudio conf talk
R
12
star
28

RmdComment

A simple comment CSS for linking in R markdown
R
11
star
29

hexbin_qld

An example of hexbinning for mapping using {h3jsr}, {dplyr}, {sf}, and {mapdeck}
R
10
star
30

milesmcbain.com

Seeing if I can make my website look any good with distill...
HTML
9
star
31

chradle

A bare bones #rstats test harness for Chrome/Chromium
R
7
star
32

tidycourse

An introduction to the tidyverse for R users. First delivery RezBaz 2017, Brisbane.
R
7
star
33

covid19

some analysis of covid19
R
6
star
34

tidy_aus_ssm

Scrubadubdub
R
6
star
35

shist

Shifting histograms - they're the shist
R
6
star
36

ghost_https_R_blog

A docker-compose.yml for an R blogger using Ghost
6
star
37

burgr_package_discovery

A short talk on ways I discover R packages, and R package stats.
CSS
5
star
38

noprobs

Tidy error data
R
5
star
39

remodel

Turn that LaTeX frown upsidedown.
R
5
star
40

shiny_SMILE

A Shiny web interface to SMILE Bayesian Networks
R
4
star
41

null_island

A stab at communicating science with VR for Bayes on the beach 2017
JavaScript
4
star
42

vr_vs_sp

Spatial meets VR with a little help from R
HTML
4
star
43

sicp_notes

SICP notes and exercises
HTML
3
star
44

lackadaisical

experments with unit testing for lazy people
3
star
45

AMSI_2017_MSBD_Talk

My personal opinions on things that are useful to know about when moving into the discipline of big data.
HTML
3
star
46

git_workshop

An introduction to git for me
3
star
47

mmstyle

My rstats code formatter
R
2
star
48

drake_make

makefile as drake plan
R
2
star
49

haircut

Give your strings a haircut with tidyverse-friendly regex.
R
2
star
50

mbtiles_example

code from my vector tiles blog post
R
2
star
51

mesh_all_the_things

Mesh all the things
R
2
star
52

unmacify_vscode

making my vscode on Mac work the same as Windows and Linux
R
1
star
53

recover_demo

stop() take a breath and recover()
R
1
star
54

MXB344

Course Materials and Assignments for MXB344
HTML
1
star
55

old_blog_source

Blogdown Source for GitHub pages site.
HTML
1
star
56

aus_ssm_census

Overlaying 2016 Census Data on the 2017 Same Sex Marriage Postal Vote
R
1
star
57

r2vr2_meshes_in_webvr

R
1
star
58

keras_facial_keypoints

A quick and dirty test of R's Keras with the Kaggle Facial keypoints data.
R
1
star
59

journalr

A repository for my proposal for an R code/data journalling tool.
HTML
1
star
60

servethis

Serve the current folder on a webserver using whatever Python is available
Shell
1
star
61

packrat_demo

An example repo using a lightweight workflow for dependency management with packrat
HTML
1
star
62

nycr_meetup_talk_code

Coded live in my talk at the New York Open Statistical Programming Meetup
R
1
star
63

r2vr3_shading

Part three of the #r2vr series. Shading a mesh.
R
1
star
64

burgr_20170913_github

Some notes for my presentation about git/github
CSS
1
star
65

r2vr1_uluru_mesh

Repository for code and data described in: `R2VR: Meshing Uluru From Polygons and Rasters`
R
1
star
66

juicr

R
1
star
67

atcursor

Get the thing at the cursor using rstudioapi
R
1
star