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
)
When using
summary_rows()with no stub, a new column is generated internally and given the namerowname. 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: