@@ -215,28 +215,51 @@ print_html.compare_parameters <- function(x,
215215 formatted_table $ Parameter <- gsub(" ]" , ci_brackets [2 ], formatted_table $ Parameter , fixed = TRUE )
216216 }
217217
218- # setup grouping for tt-backend
218+ # setup grouping for tt-backend --------------------------------------------
219+ # --------------------------------------------------------------------------
220+
221+ model_groups <- NULL
222+ by <- NULL
223+
219224 if (identical(engine , " tt" )) {
220- models <- unique(gsub(" (.*) \\ ((.*)\\ )$" , " \\ 2" , colnames(formatted_table ))[- 1 ])
221- model_groups <- lapply(models , function (model ) {
222- which(endsWith(colnames(formatted_table ), paste0(" (" , model , " )" )))
223- })
224- names(model_groups ) <- models
225- colnames(formatted_table )[- 1 ] <- gsub(" (.*) \\ ((.*)\\ )$" , " \\ 1" , colnames(formatted_table )[- 1 ])
226- } else {
227- model_groups <- NULL
225+ # find columns that contain model names, which we want to group
226+ models <- setdiff(
227+ unique(gsub(" (.*) \\ ((.*)\\ )$" , " \\ 2" , colnames(formatted_table ))[- 1 ]),
228+ c(" Component" , " Effects" , " Response" , " Group" )
229+ )
230+ # grouping only applies when we have custom column layout (with "select")
231+ # else, we don't need grouping
232+ if (any(grepl(paste0(" (" , models [1 ], " )" ), colnames(formatted_table ), fixed = TRUE ))) {
233+ model_groups <- lapply(models , function (model ) {
234+ which(endsWith(colnames(formatted_table ), paste0(" (" , model , " )" )))
235+ })
236+ names(model_groups ) <- models
237+ colnames(formatted_table )[- 1 ] <- gsub(" (.*) \\ ((.*)\\ )$" , " \\ 1" , colnames(formatted_table )[- 1 ])
238+ }
239+ if (" Component" %in% colnames(formatted_table )) {
240+ by <- c(by , " Component" )
241+ }
242+ if (" Effects" %in% colnames(formatted_table )) {
243+ by <- c(by , " Effects" )
244+ }
228245 }
229246
247+ # export table ------------------------------------------------------------
248+
230249 out <- insight :: export_table(
231250 formatted_table ,
232251 format = ifelse(identical(engine , " tt" ), " tt" , " html" ),
233252 caption = caption , # TODO: get rid of NOTE
234253 subtitle = subtitle ,
235254 footer = footer ,
236255 column_groups = model_groups ,
256+ by = by ,
237257 ...
238258 )
239259
260+ # setup gt-backend ---------------------------------------------------------
261+ # --------------------------------------------------------------------------
262+
240263 if (identical(engine , " tt" )) {
241264 out
242265 } else {
0 commit comments