From 29b97876264f2d82c3930c93ffdb712f81157e50 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Wed, 17 Jan 2024 21:56:14 -0500 Subject: [PATCH] align --- R/style_tabularray.R | 2 +- R/style_tt.R | 16 ++++++++++++++++ inst/tinytest/_tinysnapshot/html-issue58.rds | Bin 1323 -> 0 bytes inst/tinytest/_tinysnapshot/latex-align.txt | 5 ----- inst/tinytest/test-html.R | 3 ++- inst/tinytest/test-latex.R | 2 +- 6 files changed, 20 insertions(+), 8 deletions(-) delete mode 100644 inst/tinytest/_tinysnapshot/html-issue58.rds 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 0cd373d8d1288a387bb19c768899720971129505..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1323 zcmV+`1=RW>CcjlI%UZM6*Irp` z8_={iemVNC(Sxziq4UaGw_aP8{b%LFhYy#2q^IJl(*NSypZ1S_e|JDke?TgI^GO7i zW8Y@d9#jbFM~sH10nI7Xlmrn?6w|();_cNbNvF)W7o45V;zZjdh^1x{M9+ArBR^yd z9G zGN?GI6-0+lVN#vw=(RM#E=E=Anr@zA$_q&oV6o;R`~n^1Kj zgPSYenMPC4o6z$&Etjc|3yw6VQ_%=anE>H?R?Is2lEf#MX+PbE-J(OF06;P`BeqM9 zkE>r+>jeIs*2!`8?8-k7Wt)YaEqve=QLaJ%wk2y_r+<;ix=R?wR<^-N6yLEo_N=e3 zqw~RCG{fPb<9NUe@0)Hpow8}qX_rkmovpHII2FW--Ys#{v}u&*?~~Ja$^;e!ig4>Xe((Do-J=JTRN(@aGM!Qd1s$BBd$x zyrK1gBQGXL+U1sRJrr6mCPyCp9{F!ot5o~(jzDkqs~)=M0GOXk;qtmj53Bdw5gva5 zo~+(~hjSSUmfs{wkMg6r3^b1=DbBhzUMG_}f$Q^o9&Q$=@dZstc24$57zgty91oo_ z(+7f?<~JALhqaXh^XA_2W?;Hb5}&DKe(D5F2z5MxhB<7%1;ZU0hP8aLOy}yRVO%Pf z=tDSy{v4kf@wlMo+Rc;DcgjaJFi?;%%{g@B!p9gzU4YOo(GPjjnInsDD*@tRz1{%cwbmDWb3bx>(tRN6Kwt%pk6L8W<3T%3oCL#07( zd8oOCNNc0gI;gZRDs3B;) 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