hughjonesd / huxtable

An R package to create styled tables in multiple output formats, with a friendly, modern interface.
http://hughjonesd.github.io/huxtable
Other
321 stars 28 forks source link

ggplot style huxtable construction? #20

Closed puterleat closed 6 years ago

puterleat commented 7 years ago

I wonder if this is an option for huxtable? I find the pipe syntax odd when constructing tables, and dislike the idea of encouraging people to modify tables in-place. I wonder if ggplot's overloading of + would be better. This code does the lifting for ggplot: https://github.com/tidyverse/ggplot2/blob/master/R/plot-construction.r

Implementing something like this for huxtable would allow both

hx <- hux(a=1)
caption(hx) <- "My caption"

and also

hux(a=1) + caption("My table caption")

So the user doesn't have to worry about set_caption and caption (which feels a bit clunky). It's a small, but a more natural way of constructing the table, I think and consistent with ggplot which has a massive user base. Any strong feelings on this?

hughjonesd commented 7 years ago

Interesting idea and I'd encourage you to fork and implement it! I'm not sure if the + operator is a natural fit; "+" tends to imply a+b = b+a which is not always true for operations on huxtables (or in ggplot!)

David

On 12 September 2017 at 11:15, puterleat notifications@github.com wrote:

I wonder if this is an option for huxtable? I find the pipe syntax odd when constructing tables, and dislike the idea of encouraging people to modify tables in-place. I wonder if ggplot's overloading of + would be better. This code does the lifting for ggplot: https://github.com/tidyverse/ggplot2/blob/master/R/plot-construction.r

Implementing something like this for huxtable would allow both

hx <- hux(a=1) caption(hx) <- "My caption"

and also

hux(a=1) + caption("My table caption")

So the user doesn't have to worry about set_caption and caption (which feels a bit clunky). It's a small, but a more natural way of constructing the table, I think and consistent with ggplot which has a massive user base. Any strong feelings on this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hughjonesd/huxtable/issues/20, or mute the thread https://github.com/notifications/unsubscribe-auth/AFjJ95vFsSDPsVV_IuyFII5fpFuoeIBwks5shlnSgaJpZM4PUazB .

puterleat commented 7 years ago

I'm happy to have a bash at implementing it, but wanted to check your view on the overloading before making the effort because I know people get squeamish about this sort of thing sometimes. I agree that + can imply b+a, but my feeling was that here we are 'adding to what's there', in the sense of making a cake, rather than doing arithmetic. That's certainly how I'd always read the + operator when making ggplots. If not + though, is there another obvious candidate?

hughjonesd commented 7 years ago

I guess my view is I'm quite happy with the pipe syntax, it's intuitive to me. But, if you do a fork and I find it obviously works better, then I am ready to be proved wrong.