jthomasmock / gtExtras

A Collection of Helper Functions for the gt Package.
https://jthomasmock.github.io/gtExtras/
Other
193 stars 26 forks source link

gt_merge_stack not working correctly #55

Closed brett250000 closed 2 years ago

brett250000 commented 2 years ago

It appears that the gt_merge_stack function is not working correctly if you are grouping first by another field. I was just looking at the example with NFL teams and noticed that the Ravens are not in the NFC West. image

Worth noting that if you don't group by conference, the gt_merge_stack field displays correctly. image

library(gt) 
library(gtExtras)

team_df <- readRDS(url("https://github.com/nflverse/nflfastR-data/raw/master/teams_colors_logos.rds"))

team_df %>%
  dplyr::select(team_nick, team_abbr, team_conf, team_division, team_logo_wikipedia, team_wordmark) %>%
  gt(groupname_col = "team_conf") %>%
  # gt() %>%
  gt_merge_stack(col1 = team_nick, col2 = team_division) %>%
  gt_img_rows(team_logo_wikipedia) %>%
  gt_img_rows(team_wordmark)
jthomasmock commented 2 years ago

Thanks for heads up! Please install latest dev version for fix - that function is now using gtExtras::gt_index() internally which is group-safe.

library(gt) 
library(gtExtras)

team_df <- readRDS(url("https://github.com/nflverse/nflfastR-data/raw/master/teams_colors_logos.rds"))

set.seed(36)
team_df %>%
  dplyr::slice_sample(n = 12) %>%
  dplyr::select(team_nick, team_abbr, team_conf, team_division, team_logo_wikipedia, team_wordmark) %>%
  gt(groupname_col = "team_conf") %>%
  gt_merge_stack(col1 = team_nick, col2 = team_division) %>%
  gt_img_rows(team_logo_wikipedia) %>%
  gt_img_rows(team_wordmark) 

Created on 2022-06-16 by the reprex package (v2.0.1)