Skip to content

Commit

Permalink
documents
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jan 18, 2024
1 parent fc5cce4 commit 0c5ef60
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 6 deletions.
10 changes: 10 additions & 0 deletions R/format_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
#'
#' @return A data frame with formatted columns.
#' @export
#' @examples
#' dat <- data.frame(
#' a = rnorm(3, mean = 10000),
#' b = rnorm(3, 10000))
#' tab <- format_tt(dat,
#' digits = 2,
#' num_mark_dec = ",",
#' num_mark_big = " ")
#' tt(tab)
#'
format_tt <- function(x = NULL,
j = NULL,
output = NULL,
Expand Down
10 changes: 9 additions & 1 deletion R/style_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@
#' @param tabularray_inner A string that specifies the "inner" settings of a tabularray LaTeX table.
#' @param tabularray_outer A string that specifies the "outer" settings of a tabularray LaTeX table.
#' @return Returns a modified `tinytable` object with the applied styles.
#' @export
#' @template latex_preamble
#' @export
#' @examples
#' library(tinytable)
#' x <- mtcars[1:5, 1:5]
#' tab <- tt(x)
#' tab <- style_tt(tab, j = 1:5, align = "lcccr")
#' tab <- style_tt(tab, i = 2:3,
#' background = "black", color = "orange", bold = TRUE)
#'
style_tt <- function (x,
i = NULL,
j = NULL,
Expand Down
8 changes: 6 additions & 2 deletions R/tt.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#' Draw a Tiny Table
#'
#' The `tt` function renders a table in different formats (HTML, Markdown, or LaTeX) with various styling options.
#'
#' The `tt` function renders a table in different formats (HTML, Markdown, or LaTeX) with various styling options. The table can be customize with additional functions:
#'
#' * `style_tt()` to style fonts, colors, alignment, etc.
#' * `format_tt()` to format numbers, dates, strings, etc.
#' * `save_tt()` to save the table to a file.
#'
#' @param x A data frame or data table to be rendered as a table.
#' @param output The format of the output table. Can be "html", "latex", or "markdown". If NULL, the format is automatically detected in Quarto or Rmarkdown documents.
#' @param digits Number of significant digits to keep for numeric variables. When `digits` is an integer, `tt()` calls `format_tt(x, digits = digits)` before proceeding to draw the table. Users who need more control can proceed in two steps: (1) format the data with `format_tt()` or other functions, and (2) pass the formatted data to `tt()` for drawing. See `?format_tt` for more details on formating options (ex: decimal, scientific notation, dates, boolean variables, etc.).
Expand Down
11 changes: 11 additions & 0 deletions man/format_tt.Rd

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

9 changes: 9 additions & 0 deletions man/style_tt.Rd

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

9 changes: 8 additions & 1 deletion man/tt.Rd

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

10 changes: 8 additions & 2 deletions vignettes/tutorial.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ tt(x, notes = list(a = "Blah.", b = "Blah blah."))
In LaTeX and MathJax (for HTML), there are two main ways to enclose mathematical expressions, either between dollar signs or escaped parentheses: `$...$` or `\(...\)`. The first strategy [is discouraged by MathJax,](https://docs.mathjax.org/en/latest/basic/mathematics.html) because dollar signs are very common in non-mathematical contexts, which can cause rendering errors. In that spirit, `tinytable` will not render dollar-enclosed strings as mathematical expressions in HTML. Following the default MathJax settings, `tinytable` expects users to employ the escaped parentheses strategy:

```{r}
dat <- data.frame(Math = c("\\( x^2 + y^2 = z^2 \\)", "\\( \\frac{1}{2} \\)"))
dat <- data.frame(Math = c(
"\\( x^2 + y^2 = z^2 \\)",
"\\( \\frac{1}{2} \\)"
))
tt(dat) |> style_tt(align = "c")
```

Expand Down Expand Up @@ -448,7 +451,10 @@ tt(k) |>
The `color`, `background`, and `fontsize` arguments are vectorized. This allows easy specification of different colors in a single call:

```{r}
tt(x) |> style_tt(i = 1:4, color = c("red", "blue", "green", "orange"))
tt(x) |>
style_tt(
i = 1:4,
color = c("red", "blue", "green", "orange"))
```

When using a single value for a vectorized argument, it gets applied to all values:
Expand Down

0 comments on commit 0c5ef60

Please sign in to comment.