我正在尝试弄清楚如何让选择的助手在 cell_summary 中工作。
MRE:
考虑下面的示例,我们试图根据其值突出显示某些单元格。该代码适用于 cells_body,但相同的语法不适用于 cells_summary
sp500 %>%
dplyr::filter(date >= "2015-01-05" & date <= "2015-01-16") %>%
dplyr::arrange(date) %>%
dplyr::mutate(week = paste0("W", strftime(date, format = "%V"))) %>%
dplyr::select(-adj_close, -volume) %>%
gt(
rowname_col = "date",
groupname_col = "week"
) %>%
summary_rows(
fns = list(
"min",
"max",
list(label = "avg", fn = "mean")
),
fmt = ~ fmt_number(., use_seps = FALSE)
) %>%
tab_style(
style = list(
cell_text(color = "red")
),
locations = list(
cells_body(columns = 'close', rows = close<2020)
))
如果将倒数第二行替换为 cells_summary(columns = 'close', rows = min<2020), the code will fail saying "comparison (3) is possible only for atomic and list types". Is there any workaround to enable selection functions in the rows argument of cells_summary?