nutterb / pixiedust

Tables So Beautifully Fine-Tuned You Will Believe It's Magic.
179 stars 18 forks source link

Does the behavior of sprinkle need to be tweaked? #43

Closed nutterb closed 8 years ago

nutterb commented 8 years ago

Or am I doing something wrong...but based on this SO question:

http://stackoverflow.com/questions/34690118/bold-formatting-for-significant-values-in-a-rmarkdown-table

pixiedust ought to be able to do this via something like

library(dplyr)
library(magrittr)
library(tidyr)
library(pixiedust)
library(Hmisc)

# compute matrix correlation
df3 <- rcorr(as.matrix(mtcars), type="pearson")

p <- as.data.frame(df3[[3]] < 0.05)
colnames(p) <- 1:ncol(p)
p$row <- 1:nrow(p)

Sig <- gather(p, col, sig, 1:(ncol(p) - 1), convert = TRUE) %>%
  filter(sig)

dust(df3[[1]]) %>%
  sprinkle(round = 4) %>%
  sprinkle_print_method("html") %>%
  sprinkle(rows = Sig$row,
               cols = Sig$col + 1,
                bold = TRUE)

But that clearly isn't working. Instead, I have to do

x <- dust(df3[[1]]) %>%
  sprinkle(round = 4) %>%
  sprinkle_print_method("html")

for (i in 1:nrow(Sig))
{
  x <- x %>% sprinkle(rows = Sig$row[i],
                      cols = Sig$col[i] + 1,
                      bold = TRUE)
}

x

Which seems a little absurd.

nutterb commented 8 years ago

I'm going to add a fixed argument that, when TRUE, will apply the sprinkles on the fixed cell coordinates. It should probably default to

`sprinkle (x, rows, cols, ..., fixed = FALSE, recycle = c ("none", "rows", "cols", "columns"))

nutterb commented 8 years ago

This is coded and will be part of 0.7