Creating titles referencing variables when using map and gt tables

I have a large number of tibbles in a list, I'm looking for a way to add a title referencing the tibble name when using purrr::map to map gt() to the list... Thanks in advance for any assistance.

library(tidyverse)
library(gt)

# I have a dataset:
my_data <- bind_rows(
    tibble(col_a = 1:4,
           col_b = 5:8,
           col_c = letters[1:4],
           col_d = rep("set1", 4)),

    tibble(col_a = 10:20,
           col_b = 20:30,
           col_c = letters[1:11],
           col_d = rep("set2", 11)),


    tibble(col_a = 0:6,
           col_b = 20:26,
           col_c = letters[13:19],
           col_d = rep("set3", 7)),
)

# I need to create a separate table for each unique string in "col_d" 
#   BUT i want to title each table referencing the string from col_d 
#   So I split the data and remove the col_d var...

my_list <- split(my_data, my_data$col_d) %>%
    map(select, -col_d)
    
# I can use map to create individual tables

map(my_list, gt)

# Again, I want to add titles referencing the tibble name,
#   I have tried...

map(my_list, function(x) {gt(x) %>% tab_header(title = names(my_list))})
map(my_list, function(x) {gt(x) %>% tab_header(title = names(.))})

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.