From 632a7641eb06bde6e7337be0a4c76414c89a287f Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Wed, 6 Nov 2024 21:24:36 -0500 Subject: [PATCH] dcolumn severely broken: test with modelsummary too --- R/style_tabularray.R | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/R/style_tabularray.R b/R/style_tabularray.R index d6ec2932..486fea48 100644 --- a/R/style_tabularray.R +++ b/R/style_tabularray.R @@ -134,6 +134,7 @@ setMethod( } } + clean <- function(k) { k <- gsub("\\s*", "", k) k <- gsub(",+", ",", k) @@ -190,6 +191,15 @@ setMethod( x@table_string <- tabularray_insert(x@table_string, content = s, type = "inner") } + # d-alignment breaks on row headers (after alignment settings) + if (any(grepl("d", sty$align))) { + rows <- paste(sprintf("row{%s}={guard},", seq_len(x@nhead)), collapse = "\n") + x@table_string <- lines_insert(x@table_string, + rows, + "%% tabularray inner close", + position = "before") + } + # lines rec$lin <- "solid, " rec$lin <- ifelse(!is.na(rec$line_color), @@ -278,7 +288,7 @@ color_to_preamble <- function(x, col) { get_dcolumn <- function(j, x) { - siunitx <- get_option("tinytable_siunitx_table_format", default = "table-format=-%s.%s,table-align-text-before=false,table-align-text-after=false,input-symbols={-,\\*+()}") + siunitx <- get_option("tinytable_siunitx_table_format", default = "table-format=-%s.%s,table-align-text-before=false,table-align-text-after=false,input-digits={0123456789-,\\*+()}") num <- unlist(x@table_dataframe[, j]) num <- strsplit(num, "\\.") num <- lapply(num, function(k) if (length(k) == 1) c(k, " ") else k) @@ -287,6 +297,7 @@ get_dcolumn <- function(j, x) { left <- max(nchar(gsub("\\D", "", left))) right <- max(nchar(gsub("\\D", "", right))) out <- sprintf(siunitx, left, right) + out <- sprintf(siunitx, 1, 1) out <- sprintf("si={%s},", out) return(out) }