rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
1.98k stars 199 forks source link

Merge tables #1691

Open roaldarbol opened 2 months ago

roaldarbol commented 2 months ago

Prework

Proposal

I'd really like something like the tbl_merge() function from {gtsummary}, where two tables with similar columns can be "stacked".

Screenshot 2024-05-31 at 20 29 59

For the user it would look something along the lines of:

gt_merge(
  tbls = list(gt_tbl_a, gt_tbl_b),
  spanner_cols = col_that_differs,
  tab_spanner = c("**First `gt` table**", "**Second `gt` table**")
)

The assumption is of course that they are two tables with identical column names and groupings, where so the main functionality that would need to be implemented would be:

spanner_cols could then be used to automatically assign the factors of that column as the spanner titles, and as an alternative tab_spanner could be used to manually edit the spanner labels. If multiple cols are given, they would make additional nestings (if that is possible in gt).

There would be some decisions to be made about what would happen to non-matching columns (if they're present I'd argue drop as default.

roaldarbol commented 2 months ago

Just found #255 which was closed last week. Seems to be the same issue; there was no note on why it was closed. Was it completed or just considered out of scope?