From 94901f0d18e56919e85ab471b7bff5fc08c9d8c7 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Sun, 3 Nov 2024 16:04:48 -0500 Subject: [PATCH] theme_placement --- R/build_tt.R | 9 ++++++--- R/class.R | 2 +- R/style_typst.R | 1 + R/theme_tt.R | 6 +----- R/tt.R | 4 +--- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/R/build_tt.R b/R/build_tt.R index 8f45f7c2..a27b6b77 100644 --- a/R/build_tt.R +++ b/R/build_tt.R @@ -17,9 +17,12 @@ build_tt <- function(x, output = NULL) { x@output <- output - # for (th in x@lazy_theme) { - # x <- do.call(th[[1]], th[2]) - # } + for (th in x@lazy_theme) { + fn <- th[[1]] + args <- th[[2]] + args[["x"]] <- x + x <- do.call(fn, args) + } # groups must increment indices here for (idx in seq_along(x@lazy_group)) { diff --git a/R/class.R b/R/class.R index f67cf2d2..48b283f9 100644 --- a/R/class.R +++ b/R/class.R @@ -85,7 +85,7 @@ setMethod("initialize", "tinytable", function( .Object@portable <- FALSE .Object@style <- data.frame() .Object@group_tt_i <- FALSE - .Object@lazy_theme <- list(list(identity, list())) + .Object@lazy_theme <- list() # conditional: allows NULL user input if (!is.null(placement)) .Object@placement <- placement if (!is.null(caption)) .Object@caption <- caption diff --git a/R/style_typst.R b/R/style_typst.R index f1f27aa6..941b6f83 100644 --- a/R/style_typst.R +++ b/R/style_typst.R @@ -158,6 +158,7 @@ hlines <- function(k) { ymax <- k$i[1] + 1 line <- k$line[1] color <- if (is.na(k$line_color[1])) "black" else k$line_color[1] + if (grepl("^#", color)) color <- sprintf('rgb("%s")', color) width <- if (is.na(k$line_width[1])) 0.1 else k$line_width[1] width <- sprintf("%sem", width) out <- "" diff --git a/R/theme_tt.R b/R/theme_tt.R index 80de62ca..39599a59 100644 --- a/R/theme_tt.R +++ b/R/theme_tt.R @@ -1,5 +1,5 @@ theme_default <- function(x, ...) { - if (isTRUE(x@output == "html")) { + if (isTRUE(x@output %in% c("html", "typst"))) { x <- style_tt(x, bootstrap_class = "table table-borderless", i = nrow(x), @@ -13,7 +13,6 @@ theme_default <- function(x, ...) { line_color = "#d3d8dc", line_width = 0.1) } - x <- theme_tt(x, "placement") return(x) } @@ -109,7 +108,6 @@ theme_resize <- function(x, } x <- style_tt(x, finalize = fn) - x <- theme_tt(x, "placement") return(x) } @@ -139,7 +137,6 @@ theme_void <- function(x, ...) { } x <- style_tt(x, finalize = fn, bootstrap_class = "table table-borderless") - x <- theme_tt(x, "placement") return(x) } @@ -163,7 +160,6 @@ theme_grid <- function(x, ...) { } x <- style_tt(x, tabularray_inner = "hlines, vlines,", finalize = fn, bootstrap_class = "table table-bordered") - x <- theme_tt(x, "placement") return(x) } diff --git a/R/tt.R b/R/tt.R index 8ffab661..a90bf306 100644 --- a/R/tt.R +++ b/R/tt.R @@ -68,9 +68,6 @@ tt <- function(x, dots <- list(...) - if ("placement" %in% names(dots)) { - warning("The `placement` argument in `tt()` is deprecated. Please use this instead: `theme_tt(table, 'placement')`", call. = FALSE) - } # sanity checks assert_string(caption, null.ok = TRUE) @@ -134,6 +131,7 @@ tt <- function(x, if (is.null(theme)) { out <- theme_tt(out, theme = "default") + out <- theme_tt(out, theme = "placement") } else { out <- theme_tt(out, theme = theme) }