Sprinkles"

library(dplyr)

Sprinkles are used to modify the appearance of a table. The table below shows each sprinkle and for which output formats it is available.

Details regarding the use of each sprinkle are in Table 2.

Sprinkles <- read.csv(system.file("sprinkles.csv", package = "pixiedust"),
                        stringsAsFactors=FALSE)
Sprinkles[,-1] <- lapply(Sprinkles[-1], trimws)
library(pixiedust)
red <- "#A50026"
lightgreen <- "#A6DBA0"
green <- "#006837"
yellow <- "#FFFFBF"

row_bg <- which(1:nrow(Sprinkles) %% 2 == 0)

dust(Sprinkles[, -2],
     caption = "Sprinkles and their output formats") %>%
  sprinkle(cols = 2:5,
           fn = quote(ifelse(value == "x",  "&#10003;", ""))) %>%
  sprinkle(bg_pattern_by = "rows",
           border = "all",
           border_color = "#DCDCDC") %>%
  sprinkle(rows = row_bg,
           border_color = "#FFFFFF") %>%
  sprinkle_table(pad = 3) 
SprinkleDocs <- 
  read.csv(system.file("sprinkle_documentation.csv", package = "pixiedust"),
                        stringsAsFactors=FALSE,
           na = "")

SprinkleDocs[["sprinkle_name"]] <- SprinkleDocs[["sprinkle"]]

for(i in seq_along(SprinkleDocs[["sprinkle"]]))
{
  if (is.na(SprinkleDocs[["sprinkle_name"]][i])) 
    SprinkleDocs[["sprinkle_name"]][i] <- SprinkleDocs[["sprinkle_name"]][i-1]
}

SprinkleDocs <- 
  mutate(SprinkleDocs,
         bg_index = as.numeric(factor(sprinkle_name,
                                         unique(sprinkle_name))) %% 2)

rows_bg <- which(SprinkleDocs$bg_index == 0)

rows_top_border <- which(!is.na(SprinkleDocs$sprinkle))

dust(SprinkleDocs[, 1:3],
     caption = "Sprinkle Usage") %>%
  sprinkle(border = "all",
           border_color = "#DCDCDC",
           na_string = "") %>%
  sprinkle(rows = rows_bg,
           bg = "#DDDDDD",
           border = "all",
           border_color = "#FFFFFF") %>%
  sprinkle(rows = rows_top_border,
           border = "top", 
           border_color = "black",
           border_thickness = 2) 


Try the pixiedust package in your browser

Any scripts or data that you put into this service are public.

pixiedust documentation built on Oct. 10, 2023, 9:07 a.m.