gtsummary icon indicating copy to clipboard operation
gtsummary copied to clipboard

Update `modify_table_styling(cols_merge_pattern=)` for `as_gt()` after `gt::cols_merge(rows=)` implementation

Open ddsjoberg opened this issue 4 years ago • 1 comments

I like the gt package's cols_merge() function. I like that one can keep the numeric column of results and show the formatted AND merged results. What we currently do in gtsummary for confidence intervals is create a character column that is formatted and merged and add the new column to x$table_body. I would prefer to make all formatting decisions on the numeric column, allowing users to update these formatting decisions if needed at a later point.

For an average user who does not modify gtsummary tables, the update would be seamless. However, if users were updating the column headers of the "ci" column, the new column header would not be applied. One solution would be to add a check in modify_table_styling() for changes to the ci colum...if any changes are made, print a warning that the column is no longer printed.

This update needs to wait until col_merge() gets a row option. https://github.com/rstudio/gt/issues/603

ddsjoberg avatar Feb 07 '21 16:02 ddsjoberg

A first draft of the column merging is added in https://github.com/ddsjoberg/gtsummary/pull/828 and further refined in https://github.com/ddsjoberg/gtsummary/pull/856 .

  • [ ] The merging is done outside the call list that can be returned in the as_*() functions. Can it be added to the call list?
    • This is complete, except for in as_gt(). Once gt::cols_merge(rows=) is implemented, it can be moved to the call list. rstudio/gt#603
  • [ ] Add modify_cols_merge() function to wrap modify_table_styling() after gt::cols_merge(rows=) implementation
  • [x] Need to add a pattern argument to modify_table_styling()
  • [x] The implementation is will be somewhat different for gt compared to the other engines. The other engines use the column from x$table_styling$cols_merge to identify which column to replace with the formatted column in pattern. But the cols_merge() function will use the first column in pattern. Perhaps we should omit the column column from x$table_styling$cols_merge altogether and merely infer the first column?
  • [x] Need to implement a way to undo merging (perhaps an NA pattern?) use most recently passed merge (perhaps one merge per column?)
  • [x] Current implementation requires a rows= argument. Need to update

ddsjoberg avatar Mar 25 '21 01:03 ddsjoberg