0

I'm trying to figure out how to get the select helpers to work in cell_summary.

MRE:

Consider the example below where we are trying to highlight certain cells based on its value. The code works for cells_body, but the same syntax fails for 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)
    )) 

If the 2nd last line were to be replaced with 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?

trian
  • 23
  • 2

0 Answers0