Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Dec 10, 2024
1 parent 2260238 commit 142589f
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 298 deletions.
10 changes: 5 additions & 5 deletions R/group_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
#' @param ... Other arguments are ignored.
#' @return An object of class `tt` representing the table.
#' @param indent integer number of `pt` to use when indenting the non-labelled rows.
#' @template limitations_word_markdown
#' @details
#' Warning: The `style_tt()` can normally be used to style the group headers, as expected, but that feature is not available for Markdown and Word tables.
#' @examples
#'
#' # vector of row labels
#' dat <- data.frame(
#' label = c("a", "a", "a", "b", "b", "c", "a", "a"),
#' x1 = rnorm(8),
#' x2 = rnorm(8))
#' label = c("a", "a", "a", "b", "b", "c", "a", "a"),
#' x1 = rnorm(8),
#' x2 = rnorm(8))
#' tt(dat[, 2:3]) |> group_tt(i = dat$label)
#'
#' # named lists of labels
Expand Down Expand Up @@ -51,7 +52,6 @@
#' group_tt(j = list("Hello" = 1:2, "World" = 3:4, "Hello" = 5:6)) |>
#' group_tt(j = list("Foo" = 1:3, "Bar" = 4:6))
#'

group_tt <- function(x, i = NULL, j = NULL, indent = 1, ...) {
# ... is important for ihead passing

Expand All @@ -78,7 +78,7 @@ group_tt <- function(x, i = NULL, j = NULL, indent = 1, ...) {
x@ngroupi <- length(i)
x@nrow <- x@nrow + x@ngroupi
x@group_i_idx <- as.numeric(i)

if (isTRUE(indent > 0)) {
idx_indent <- setdiff(seq_len(nrow(x)), i + seq_along(i) - 1)
x <- style_tt(x, i = idx_indent, j = 1, indent = indent)
Expand Down
493 changes: 244 additions & 249 deletions R/style_tt.R

Large diffs are not rendered by default.

37 changes: 18 additions & 19 deletions R/tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#' @param x A data frame or data table to be rendered as a table.
#' @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. Note that this will apply all default argument values of `format_tt()`, such as replacing `NA` by "". Users who need more control can use the `format_tt()` function instead.
#' @param caption A string that will be used as the caption of the table. This argument should *not* be used in Quarto or Rmarkdown documents. In that context, please use the appropriate chunk options.
#' @param width Table or column width.
#' - Single numeric value smaller than or equal to 1 determines the full table width, in proportion of line width.
#' @param width Table or column width.
#' - Single numeric value smaller than or equal to 1 determines the full table width, in proportion of line width.
#' - Numeric vector of length equal to the number of columns in `x` determines the width of each column, in proportion of line width. If the sum of `width` exceeds 1, each element is divided by `sum(width)`. This makes the table full-width with relative column sizes.
#' @param theme Function or string.
#' - String: `r paste(setdiff(names(theme_dictionary), "default"), collapse = ", ")`
Expand All @@ -30,32 +30,33 @@
#' @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.
#'
#'
#' The table object has S4 slots which hold information about the structure of the table. Relying on or modifying the contents of these slots is strongly discouraged. Their names and contents could change at any time, and the `tinytable` developers do not consider changes to the internal structure of the output object to be a "breaking change" for versioning or changelog purposes.
#' @template dependencies
#' @template latex_preamble
#' @template limitations_word_markdown
#' @template global_options
#'
#'
#' @examples
#' library(tinytable)
#' x <- mtcars[1:4, 1:5]
#'
#' tt(x)
#'
#'
#' tt(x,
#' theme = "striped",
#' width = 0.5,
#' caption = "Data about cars.")
#'
#' theme = "striped",
#' width = 0.5,
#' caption = "Data about cars.")
#'
#' tt(x, notes = "Hello World!")
#'
#' fn <- list(i = 0:1, j = 2, text = "Hello World!")
#' tab <- tt(x, notes = list("*" = fn))
#' print(tab, "latex")
#'
#'
#' k <- data.frame(x = c(0.000123456789, 12.4356789))
#' tt(k, digits=2)
#'
#' tt(k, digits = 2)
#'
#' @export
tt <- function(x,
digits = get_option("tinytable_tt_digits", default = NULL),
Expand All @@ -66,8 +67,6 @@ tt <- function(x,
rownames = get_option("tinytable_tt_rownames", default = FALSE),
escape = get_option("tinytable_tt_escape", default = FALSE),
...) {


dots <- list(...)

# sanity checks
Expand All @@ -91,20 +90,20 @@ tt <- function(x,
# it might be dangerous to leave non-numerics, but what about dates and other character-coercibles?
for (i in seq_along(x)) {
if (is.factor(x[[i]])) {
x[[i]] <- as.character(x[[i]])
x[[i]] <- as.character(x[[i]])
}
}

assert_numeric(width, lower = 0, null.ok = TRUE)
if (!length(width) %in% c(0, 1, ncol(x))) {
msg <- sprintf("The `width` argument must have length 1 or %s.", ncol(x))
stop(msg, call. = FALSE)
msg <- sprintf("The `width` argument must have length 1 or %s.", ncol(x))
stop(msg, call. = FALSE)
}
if (sum(width) > 1) {
width <- width / sum(width)
width <- width / sum(width)
}

# bind the row names if the user explicitly asks for it in global option.
# bind the row names if the user explicitly asks for it in global option.
# Same name as tibble::rownames_to_column()
assert_flag(rownames)
if (isTRUE(rownames) && !is.null(row.names(x))) {
Expand Down
8 changes: 8 additions & 0 deletions man-roxygen/limitations_word_markdown.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#' @section Word and Markdown limitations:
#'
#' Markdown and Word tables only support these styles: italic, bold, strikeout. The `width` arugment is also unavailable
#' Moreover, the `style_tt()` function cannot be used to style headers inserted by the `group_tt()` function;
#' instead, you should style the headers directly in the header definition using markdown syntax:
#' `group_tt(i = list("*italic header*" = 2))`. These limitations are due to the fact that there is no markdown
#' syntax for the other options, and that we create Word documents by converting a markdown table to .docx
#' via the Pandoc software.
17 changes: 14 additions & 3 deletions man/group_tt.Rd

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

45 changes: 27 additions & 18 deletions man/style_tt.Rd

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

19 changes: 15 additions & 4 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 142589f

Please sign in to comment.