Skip to content

The cells_summary() groups arg not working with tidyselect semantics #785

@rich-iannone

Description

@rich-iannone

Using the cells_summary() location helper function requires use of non-default values to get it to work.

The signature for the function is:

cells_summary(
  groups = everything(),
  columns = everything(),
  rows = everything()
)

Here's an MRE which results in an error (expectation is that all summary rows should be styled):

library(gt)

gtcars %>% 
  gt(rowname_col = "model", groupname_col = "mfr") %>%
  summary_rows(
    groups = c("Ford", "Ferrari"),
    columns = year,
    fns = list(`latest year` = ~ max(.)),
    formatter = fmt_number,
    decimals = 0,
    use_seps = FALSE
  ) %>%
  tab_style(
    style = list(
      cell_fill(color = background_color),
      cell_text(color = text_color)
    ),
    locations = cells_summary(groups = everything())
  )
Error: `everything()` must be used within a *selecting* function.
ℹ See <https://tidyselect.r-lib.org/reference/faq-selection-context.html>.
Run `rlang::last_error()` to see where the error occurred. 

With groups in cells_summary(), a vector group ID values must be provided (i.e., groups = "Ferrari" works).

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions