Extend glue. You can specify inside the template, operations like collapsing. Most importantly on can specify group_by operations on a data frame. Look at the vignette for details and examples.
The package is hosted on r-universe. To install it run:
options(repos = c( skranz = 'https://skranz.r-universe.dev', CRAN = 'https://cloud.r-project.org')) install.packages('xglue')