@@ -155,35 +155,44 @@ tbl_format_header.SE_print_abstraction <- function(x, setup, ...) {
155155 number_of_total_rows = (x | > attr(" number_of_features" )) * (x | > attr(" number_of_samples" ))
156156
157157 printed_colnames <- x | > attr(" printed_colnames" )
158-
159- # Identify covariate columns: those from colData
160- # Assume covariate columns are after .sample, .feature, .count, and assay columns
161- # We'll use heuristics: find the first and last covariate column positions
162158
163- # .feature and .samples SHOULD BE A GLOBAL VARIABLE CREATED ONES
164- # SO IT CAN BE CHANGED ACROSS THE PACKAGE
165- # THIS BREAKS IF I HAVE ROWDATA
166- covariate_candidates <- setdiff(printed_colnames , c(" .sample" , " .feature" , " |" , assay_names ))
167- # Remove gene/rowData columns if possible (e.g., chromosome, gene_feature, ...)
168- # For now, just use all columns after .count and before gene_feature as covariates
169- first_covariate <- which(printed_colnames %in% covariate_candidates )[1 ]
170- last_covariate <- which(printed_colnames %in% covariate_candidates ) | > tail(1 )
171- last_covariate <- if (length(last_covariate ) > 0 ) max(last_covariate ) else NA
172-
173- # Only add header if there are covariate columns
174- covariate_header <- NULL
159+ # Find the positions of all '|' characters in the string
160+ pipe_positions <- stringr :: str_locate_all(printed_colnames , " \\ |" )[[1 ]][, " start" ]
175161
176- if (! is.na(first_covariate ) && ! is.na(last_covariate ) && last_covariate > = first_covariate ) {
177- covariate_header <- format_covariate_header(
178- separator_row = separator_row ,
179- printed_colnames = printed_colnames ,
180- covariate_names = covariate_names ,
181- number_of_total_rows = number_of_total_rows ,
182- label = " COVARIATES "
183- )
184- covariate_header <- cli :: col_br_blue(covariate_header )
162+ # Calculate character length to the start of the second '|'
163+ chars_to_second_pipe <- pipe_positions [2 ] - 2
164+
165+ # Check if there's a third pipe
166+ if (length(pipe_positions ) > = 3 ) {
167+ # Calculate character length between second and third pipe
168+ chars_to_third_pipe <- pipe_positions [3 ] - pipe_positions [2 ] - 2
169+ } else {
170+ # Calculate character length to the end of the line
171+ chars_to_third_pipe <- nchar(printed_colnames ) - pipe_positions [2 ]
185172 }
186173
174+ label = " COVARIATES "
175+ label_length <- nchar(label )
176+
177+ # Center the label in the total covariate width, using only dashes and the label
178+ left_pad <- floor((chars_to_third_pipe - label_length ) / 2 )
179+ right_pad <- chars_to_third_pipe - label_length - left_pad
180+ merged_label <- paste0(
181+ paste(rep(" -" , left_pad ), collapse = " " ),
182+ label ,
183+ paste(rep(" -" , right_pad ), collapse = " " )
184+ )
185+
186+ # Add '|' at the beginning and end
187+ merged_label <- paste0(" |" , merged_label , " |" )
188+
189+ # Pad with the spaces until chars to second pipe
190+ merged_label <- c(paste(rep(" " , chars_to_second_pipe ), collapse = " " ), merged_label ) | >
191+ paste0(collapse = " " )
192+
193+ covariate_header <- cli :: col_br_blue(merged_label )
194+
195+
187196 # Compose the main header as before
188197 if (all(names2(named_header ) == " " )) {
189198 header <- named_header
0 commit comments