Gt: Several problems with `summary_rows()`

Created on 3 Nov 2018  Â·  2Comments  Â·  Source: rstudio/gt

The summary_rows() function is problematic in many cases. It seems to only work at all when:

  • there is a stub column (using any of the methods to create a stub column with gt())
  • there are row groups (using any of the methods to create groups with gt() or group_by(data) %>% gt())

Also, there are usability problems with the arguments:

  • the 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)
  • the 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:

  1. Grand Summary Rows (creates rows at the bottom, not concerned with individual groups at all) – becomes the default behavior
.... %>%
summary_rows(
  groups = NULL,
  columns = vars(....),
  fns = list(....))
  1. Summary Rows for All Groups (creates rows at the bottom of each group, uses a sentinel function like all_groups())
.... %>%
summary_rows(
  groups = all_groups(),
  columns = vars(....),
  fns = list(....))
  1. Summary Rows for Selected Groups (creates rows at the bottom of each group specified)
.... %>%
summary_rows(
  groups = vars(....),
  columns = vars(....),
  fns = list(....))

Very open to discussion on this topic.

[3] Advanced [3] High ♨︎ Critical ★ Enhancement ☹︎ Bug

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!

All 2 comments

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...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vincentarelbundock picture vincentarelbundock  Â·  4Comments

TuSKan picture TuSKan  Â·  6Comments

jenniferp96 picture jenniferp96  Â·  4Comments

courtiol picture courtiol  Â·  3Comments

higgi13425 picture higgi13425  Â·  3Comments