nutterb / pixiedust

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

Offer simpler option to set column alignment #116

Open dkyleward opened 6 years ago

dkyleward commented 6 years ago

One of the things that kable and htmlTable get right is that they offer a concise way to set alignment for all columns. In kable(), that's align = "llrc". One letter ("L", "R", or "C") for each column.

As a first step, could you expand halign to accept a vector of "left", "center", and "right"? If rows = NULL you simply start with the far left column and stop when you run out of elements in halign.

nutterb commented 6 years ago

The following works as of version 0.8.3

The challenge with multiple inputs is that, unlike kable, pixiedust maintains an interface to work across rows and columns. With multiple inputs, it isn't always obvious if inputs need to be recycled over the rows or the columns. If you set the argument recycle = "columns" it will work with the multiple inputs.

I'm contemplating changes to some of the assumptions in #114 but have yet to make a decision.

library(pixiedust)
dust(head(mtcars)) %>% 
  sprinkle(cols = 1:2,
           width = c(20, 1.5),
           width_units = c("px", "in"),
           recycle = "columns") %>% 
  medley_all_borders() %>%
  sprinkle_print_method("html")
dkyleward commented 6 years ago

OK, that makes sense. Perhaps a col_halign = "llrr" would offer a quick option while preserving the detailed control that currently exists? It avoids having to rethink your core approach, and at first glance, I think I like it better than #114. In particular, it's nice that in some of those other packages align = "lr" repeats the right alignment for all subsequent columns. If I have lots of columns, this would be much more user-friendly.

Thanks!