Skip to content

When using summary_rows() with no stub, there is a possibility for column name duplication #749

Description

@rich-iannone

When using summary_rows() with no stub, a new column is generated internally and given the name rowname. This can conflict with a column that has the same name, generating duplicate column names and not erroring at that instant. Instead, the error occurs at the build phases and the error messages are uninformative.

Here is some code that demonstrates some of the ways this might happen:

library(gt)
library(tidyverse)

# Case where the `rowname` column conflicts with the
# similarly named `rowname` column in the internal summary df
exibble %>%
  rename(rowname = row) %>%
  # gt(rowname_col = NULL) %>% # doesn't work, Error: Column name `rowname` must not be duplicated.
  # gt(rowname_col = NULL, groupname_col = "group") %>% # doesn't work, Error: Column name `rowname` must not be duplicated.
  # gt(rowname_col = "char") %>% # works, `mapply()` warnings appear
  # gt(rowname_col = "char", groupname_col = "group") %>% # works, `mapply()` warnings appear
  grand_summary_rows(
    columns = c(num, currency),
    fns = list(
      min = ~min(., na.rm = TRUE),
      max = ~max(., na.rm = TRUE),
      avg = ~mean(., na.rm = TRUE)),
    formatter = fmt_number
  )

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions