Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a better error message for non-existent summary or grand summary rows #1834

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

olivroy
Copy link
Collaborator

@olivroy olivroy commented Aug 15, 2024

Summary

For discussion. I need to think about this a bit more. Maybe could use summary it can find.

A case like the following could be considered too.

My PR seems to address a very narrow problem compared to what's proposed in #1608.

# Create a table from `mtcars` that has all the different components
data <-
  mtcars %>%
  gt(rownames_to_stub = TRUE) %>%
  cols_move_to_start(columns = c("gear", "carb")) %>%
  tab_stubhead(label = "cars") %>%
  cols_hide(columns = "mpg") %>%
  cols_hide(columns = "vs") %>%
  tab_row_group(
    label = "Mercs",
    rows = contains("Merc"),
  ) %>%
  tab_row_group(
    label = "Mazdas",
    rows = contains("Mazda"),
  ) %>%
  tab_options(row_group.default_label = "Others") %>%
  tab_spanner(
    label = "gear_carb_cyl",
    id = "gcc",
    columns = c(gear, carb, cyl)
  ) %>%
  row_group_order(groups = c("Mazdas", "Mercs")) %>%
  cols_merge_range(
    col_begin = "disp",
    col_end = "drat"
  ) %>%
  tab_header(
    title = "Title",
    subtitle = "Subtitle"
  ) %>%
  tab_source_note(source_note = "this is a source note") %>%
  summary_rows(
    groups = c("Mazdas", "Mercs"),
    columns = c(hp, wt, qsec),
    fns = list(
      ~mean(., na.rm = TRUE),
      ~sum(., na.rm = TRUE)
    )
  ) %>%
  grand_summary_rows(
    columns = c(hp, wt),
    fns = list(
      ~mean(., na.rm = TRUE),
      ~sum(., na.rm = TRUE)
    )
  )
# My PR doesn't solve the fact that you can't send all summaries here due to not having summary rows everywhere.
data %>%
    tab_footnote("footnote in summary", cells_summary())
#> Error in `tab_footnote()`:
#> ! Can't add footnote "footnote in summary".
#> Caused by error:
#> ! `everything()` must be used within a *selecting* function.
# need the following:
data %>%
    tab_footnote("footnote in summary", cells_summary(c(1, 3)))

Related GitHub Issues and PRs

Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant