Conversation
cderv
left a comment
There was a problem hiding this comment.
I think I need a bit more context about this new feature. First let me share my understanding
- I see gt as a visualization tool (like ggplot) but for tables. So I would expect to find in gt only some features and functions related to how to represent tables, and tweaks styling / layout.
- Tables data is for me something that should be passed to gt and prepare upstream in the pipeline.
So why reimplement in gt a function to add some rows ? There is already one in tibble::add_row(), even reexported as dplyr::add_row() , and it seems you don't use it in the function either. Is this on purpose ? Hard to program with maybe ?
I understand the why for the original issue "add spacer rows" as I see that as layout issue, but isn't it too much to maintain to make your own add rows function in gt ?
Maybe I missing the point, and there is some specific use case you have in mind. I just prefer to have the full context before doing a more thorough review.
Absolutely, this is worth some explanation. When we originally planned the API for gt (in a Google doc, some time back in early 2018), the thinking was all the data was going to come into gt and be immutable. The only thing left for gt to do was to lightly format values, style parts of the table, and ensure that different outputs were supported. However, it was soon apparent that people wanted to do things a bit outside of the scope of that. We soon had the ability to move columns around, arrange rows within different groups, and add summary rows. These were all things that could be done in dplyr! It felt to some that this was a design mistake and there should be a clear line between data manipulation and data presentation. But, after some time, and quite a lot of experimentation, we found that doing these data manipulation things in gt felt pretty good and natural. It's hard to make a table summary and add it to an existing table in dplyr (we tried it, not fun!). It turned out that producing that data in gt was not such a bad thing. And later, with extra development, we made it even better by combining formatting with the creation of summary rows. Turns out that the community pushed us in these weird directions. It was uncomfortable at first, but it's what they really wanted (and they're using these features a lot it seems). A lot of this can feel as though the authorship is less focused but we see some of the same design decisions also in ggplot (like fitting a trendline through a scatterplot; that data was manufactured inside the API). It's much the same with the |
|
Thanks Christoph! It's good to have a second pair of eyes and I appreciate you taking the time to take a look at this. |
This PR is focused on the addition of a new function called
rows_add(). It allows the user to supply the new row data through name value pairs. The new rows are added to the bottom of the table by default but can be added internally though by using either the.beforeor.afterarguments. If entirely empty rows need to be added, the.n_emptyoption provides a means to specify the number of blank (i.e., allNA) rows to be inserted into the table.Here is a basic example, where a new row is added to the bottom of the gt table.
If you wanted to place a row somewhere in the middle of the table, we can use either of the
.beforeor.afterarguments inrows_add():Another application is starting from nothing (really just the definition of columns) and building up a table using nothing but
rows_add(). This might be useful in interactive or programmatic applications. Here's an example where two columns are defined with dplyr'stibble()function but no rows are present initially; with two calls ofrows_add(), two separate rows are added.Fixes: #698