diff --git a/R/style_tabularray.R b/R/style_tabularray.R index 5d2f7f55..a88711d7 100644 --- a/R/style_tabularray.R +++ b/R/style_tabularray.R @@ -37,7 +37,7 @@ style_tabularray <- function(x, # colspan requires cell level, so we keep the full settings DF if (is.null(colspan)) { if (is.null(i) && is.null(j)) { - settings <- unique(settings[, c("j", "tabularray"), drop = FALSE]) + settings <- unique(settings[, c("i", "tabularray"), drop = FALSE]) } else if (is.null(i)) { settings <- unique(settings[, c("j", "tabularray"), drop = FALSE]) } else if (is.null(j)) { diff --git a/R/style_tt.R b/R/style_tt.R index 9ef92226..7e754951 100644 --- a/R/style_tt.R +++ b/R/style_tt.R @@ -115,6 +115,22 @@ style_tt_lazy <- function (x, # align can be "c" or "clrrlc"takes many possible values assert_string(align, null.ok = TRUE) + + if (!is.null(align)) { + if (nchar(align) == 1) { + assert_choice(align, c("c", "l", "r")) + } else { + align_split <- strsplit(align, split = "")[[1]] + for (align_character in align_split){ + assert_choice(align_character, c("c", "l", "r")) + } + if (is.null(j)) { + msg <- "Please specify the `j` argument." + stop(msg, call. = FALSE) + } + } + } + nalign <- if (is.null(j)) meta(x, "ncols") else length(j) if (!is.null(align)) { align <- strsplit(align, split = "")[[1]] diff --git a/inst/tinytest/_tinysnapshot/html-issue58.rds b/inst/tinytest/_tinysnapshot/html-issue58.rds deleted file mode 100644 index 0cd373d8..00000000 Binary files a/inst/tinytest/_tinysnapshot/html-issue58.rds and /dev/null differ diff --git a/inst/tinytest/_tinysnapshot/latex-align.txt b/inst/tinytest/_tinysnapshot/latex-align.txt index 21ffd88f..ec6f1986 100644 --- a/inst/tinytest/_tinysnapshot/latex-align.txt +++ b/inst/tinytest/_tinysnapshot/latex-align.txt @@ -6,15 +6,10 @@ { %% tabularray inner open colspec={Q[]Q[]Q[]Q[]Q[]}, column{1}={halign=c,}, -cell{1}{1}={}{halign=c,}, column{2}={halign=c,}, -cell{1}{2}={}{halign=c,}, column{3}={halign=l,}, -cell{1}{3}={}{halign=l,}, column{4}={halign=l,}, -cell{1}{4}={}{halign=l,}, column{5}={halign=r,}, -cell{1}{5}={}{halign=r,}, } %% tabularray inner close \toprule mpg & cyl & disp & hp & drat \\ \midrule %% TinyTableHeader diff --git a/inst/tinytest/test-html.R b/inst/tinytest/test-html.R index e294a8cf..f534ee64 100644 --- a/inst/tinytest/test-html.R +++ b/inst/tinytest/test-html.R @@ -28,7 +28,8 @@ tab <- tt(x, output = "html") |> expect_equal_to_reference(clean(tab), "_tinysnapshot/html-vectorized_color_j.rds") # Issue #58 -tab <- tt(iris[1:10,], output = "html", align = "ccccc") |> +tab <- tt(iris[1:10,], output = "html") |> + style_tt(align = "c") |> group_tt(j = list("Sepal" = 1:2, "Petal" = 3:4)) expect_equal_to_reference(clean(tab), "_tinysnapshot/html-issue58.rds") diff --git a/inst/tinytest/test-latex.R b/inst/tinytest/test-latex.R index 1e934dd4..edac0862 100644 --- a/inst/tinytest/test-latex.R +++ b/inst/tinytest/test-latex.R @@ -15,7 +15,7 @@ expect_snapshot_print( # Align expect_snapshot_print( - tt(x, output = "latex", align = "ccllr"), + tt(x, output = "latex") |> style_tt(j = 1:5, align = "ccllr"), label = "latex-align") # Themes