nutterb / pixiedust

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

Format cells based on their values #87

Closed dkyleward closed 7 years ago

dkyleward commented 7 years ago

First, I just started using this package, and I love it. Nice work.

My apologies if I missed it in the help, but I'd love to see a method to apply various formatting options based on cell values. As an example, I have a matrix with positive and negative values. It would be great to show all the negative values in red, values above a certain absolute value in bold, etc.

dust(object) %>%
  sprinkle(
    rows = c(1:5), cols = c(1:5), font_color = "red",
    where = funs(. < 0)
  )

Thanks again!

nutterb commented 7 years ago

This is actually in the works (See Issues #56 and #67). There are some options available in the devel branch (devtools::install_github("nutterb/pixiedust", ref = "devel")).

Consider the following examples:

dust(mtcars) %>% 
  sprinkle(logical_rows = quote(mpg < 15),
           cols = "mpg",
           font_color = "red") %>% 
  sprinkle_print_method("html")

dust(mtcars) %>% 
  sprinkle(cols = "gear",
           discrete = "bg") %>% 
  sprinkle_print_method("html")

dust(mtcars) %>% 
  sprinkle(cols = "hp",
           gradient = "bg") %>% 
  sprinkle_print_method("html")

But keep in mind that this is still in development. In the end, I'd like to get rid of the logical_rows argument and just use rows, but that isn't working yet. When I get it working, logical_rows will probably go away. It could be a few more months before I have the devel branch ready for release. I'm doing a pretty serious overhaul. The current API won't be affected, but the changes in the background will make it far easier to maintain than what I've put together. Anyway, I will need to be convinced that I haven't broken anything serious before I release it.