Skip to content

Commit

Permalink
tt(escape = TRUE) (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock authored Sep 22, 2024
1 parent bf1fd5b commit 2815210
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: tinytable
Type: Package
Title: Simple and Configurable Tables in 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', and 'Typst' Formats
Description: Create highly customized tables with this simple and dependency-free package. Data frames can be converted to 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', or 'Typst' tables. The user interface is minimalist and easy to learn. The syntax is concise. 'HTML' tables can be customized using the flexible 'Bootstrap' framework, and 'LaTeX' code with the 'tabularray' package.
Version: 0.4.0.4
Version: 0.4.0.5
Imports:
methods
Depends:
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

New:

* `tt()` gets an `escape` argument. Thanks to Cameron Patrick for the feature request.
* The `i` argument in `style_tt()` now accepts a logical matrix of same dimensions as `x`, to style specific cells, rather than all combinations of `i` and `j` vectors. Thanks to @dhicks for the feature request #329.
* `style_tt()` gets new `output` argument for conditional styling based on output format.
* `names()` method now supported for both returning column names and re-assingning them. Issue #332.
Expand Down
6 changes: 6 additions & 0 deletions R/tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#' * A named list inserts a list with the name as superscript: `list("a" = list("Hello World"))`
#' * A named list with positions inserts markers as superscripts inside table cells: `list("a" = list(i = 0:1, j = 2, text = "Hello World"))`
#' @param rownames Logical. If `TRUE`, rownames are included as the first column
#' @param escape Logical. If `TRUE`, escape special characters in the table. Equivalent to `format_tt(tt(x), escape = TRUE)`.
#' @param ... Additional arguments are ignored
#' @return An object of class `tt` representing the table.
#'
Expand Down Expand Up @@ -62,6 +63,7 @@ tt <- function(x,
width = get_option("tinytable_tt_width", default = NULL),
theme = get_option("tinytable_tt_theme", default = NULL),
rownames = get_option("tinytable_tt_rownames", default = FALSE),
escape = get_option("tinytable_tt_escape", default = FALSE),
...) {


Expand Down Expand Up @@ -140,5 +142,9 @@ tt <- function(x,
out <- theme_tt(out, "placement", latex_float = dots[["placement"]])
}

if (isTRUE(escape)) {
out <- format_tt(out, escape = TRUE)
}

return(out)
}
8 changes: 8 additions & 0 deletions inst/tinytest/test-escape.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ set.seed(1024) # reproducibility of html unique IDs
tab <- tt(dat) |> format_tt(escape = TRUE) |> save_tt("latex")
expect_snapshot_print(tab, "escape-latex")

tab <- tt(dat, escape = TRUE) |> save_tt("latex")
expect_snapshot_print(tab, "escape-latex")

options(tinytable_tt_escape = TRUE)
tab <- tt(dat) |> save_tt("latex")
expect_snapshot_print(tab, "escape-latex")
options(tinytable_tt_escape = FALSE)

# escape columns
dat <- data.frame("blah_blah" = 1:2)
tab <- tt(dat) |> format_tt(escape = TRUE) |> save_tt("latex")
Expand Down
3 changes: 3 additions & 0 deletions man/tt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2815210

Please sign in to comment.