From da962fd561ce88be1c66ffdbc41caf2a92d1137d Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Thu, 12 Dec 2024 18:01:50 -0500 Subject: [PATCH] sanity_i allows logical matrix --- R/sanity.R | 2 ++ inst/tinytest/test-i_j.R | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/R/sanity.R b/R/sanity.R index 38c56328..591ed3f4 100644 --- a/R/sanity.R +++ b/R/sanity.R @@ -16,6 +16,8 @@ sanitize_i <- function(i, x, pre_group_i = FALSE, lazy = TRUE) { if (is.character(i)) { assert_choice(i, c("notes", "caption")) return(i) + } else if (is.matrix(i) && is.logical(i)) { + return(i) } out <- seq_len(nrow(x)) assert_numeric(i, null.ok = TRUE, name = "i") diff --git a/inst/tinytest/test-i_j.R b/inst/tinytest/test-i_j.R index 3014badb..09c8cd09 100644 --- a/inst/tinytest/test-i_j.R +++ b/inst/tinytest/test-i_j.R @@ -21,4 +21,11 @@ tab <- tt(x) |> format_tt(i = 3:4, j = c(5:6), num_fmt = "decimal", digits = 2) expect_snapshot_print(tab, "i_j-format_tt_i_01") + +cormat <- data.frame(cor(mtcars[1:5])) +tab <- tt(cormat, digits = 2) |> + style_tt(i = abs(cormat) > .8, background = "black", color = "white") +expect_equal(dim(tab), c(5, 5)) + + options(tinytable_print_output = NULL)