The summary_rows() function is problematic in many cases. It seems to only work at all when:
gt())gt() or group_by(data) %>% gt())Also, there are usability problems with the arguments:
groups argument can't use group names enclosed in vars() but only c() (this is more of a consistency issue since a lot of label selections can use both) columns argument (even though the default is NULL) must contain either a vars() or c() with columns to be included in the aggregation for the selected groups: NULL or TRUE yield errors (Error: `.vars` must be a character/numeric vector or a `vars()` object, not logical)For reference, this currently works:
gt(iris %>% tibble::rownames_to_column(), groupname_col = "Species") %>%
summary_rows(
columns = vars(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width),
fns = list(avg = "mean", `s.d.` = "sd"))
But the user may not want/need row captions and also wouldn't like to type out all of the column names.
There is also another issue (https://github.com/rstudio/gt/issues/38) that puts forward that summary_rows() should also create a 'grand summary', that is, include all rows (irrespective of any groups they may or may not be part of) and create summary rows at the bottom of the table.
Thus, to plan for this extra functionality, the groups argument might take in the following to perform the intended actions:
.... %>%
summary_rows(
groups = NULL,
columns = vars(....),
fns = list(....))
all_groups()).... %>%
summary_rows(
groups = all_groups(),
columns = vars(....),
fns = list(....))
.... %>%
summary_rows(
groups = vars(....),
columns = vars(....),
fns = list(....))
Very open to discussion on this topic.
Please, please, please, I will sell my soul for an R package that will let me make pretty tables with grand totals. 99% of the time, I need to produce output as boring, conservative tables for boring, conservative lawyers. And they have to have totals.
Edited to add: I really need all three of the summary functions you listed. I work in a financial/legal field and the bulk of our deliverables are in the form of formatted tables that must have subtotals and grand totals.
This package is otherwise so incredibly lovely. Please save me from Excelhell!
I think now it's impossible to use data of other columns in summary_rows(), correct?
For example, I may have a table with two columns, one is Weight anther is Value. I may need to calculate the weighted.mean(Value, Weight). However, it seems no way to access Weight's data when calculating Value...
Most helpful comment
Please, please, please, I will sell my soul for an R package that will let me make pretty tables with grand totals. 99% of the time, I need to produce output as boring, conservative tables for boring, conservative lawyers. And they have to have totals.
Edited to add: I really need all three of the summary functions you listed. I work in a financial/legal field and the bulk of our deliverables are in the form of formatted tables that must have subtotals and grand totals.
This package is otherwise so incredibly lovely. Please save me from Excelhell!