group_tt {tinytable} | R Documentation |
Spanning labels to identify groups of rows or columns
Description
Spanning labels to identify groups of rows or columns
Usage
group_tt(
x,
i = getOption("tinytable_group_i", default = NULL),
j = getOption("tinytable_group_j", default = NULL),
indent = getOption("tinytable_group_indent", default = 1),
...
)
Arguments
x |
A data frame or data table to be rendered as a table. |
i |
A vector of labels with length equal to the number of rows in
|
j |
String or named list
|
indent |
integer number of |
... |
Other arguments are ignored. |
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.
Value
An object of class tt
representing the table.
Word and Markdown limitations
Markdown and Word tables only support these styles: italic, bold, strikeout. The width
argument 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.
Examples
# vector of row labels
dat <- data.frame(
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
tt(mtcars[1:10, 1:5]) |>
group_tt(
i = list(
"Hello" = 3,
"World" = 8
),
j = list(
"Foo" = 2:3,
"Bar" = 4:5
)
)
dat <- mtcars[1:9, 1:8]
tt(dat) |>
group_tt(i = list(
"I like (fake) hamburgers" = 3,
"She prefers halloumi" = 4,
"They love tofu" = 7
))
tt(dat) |>
group_tt(
j = list(
"Hamburgers" = 1:3,
"Halloumi" = 4:5,
"Tofu" = 7
)
)
x <- mtcars[1:5, 1:6]
tt(x) |>
group_tt(j = list("Hello" = 1:2, "World" = 3:4, "Hello" = 5:6)) |>
group_tt(j = list("Foo" = 1:3, "Bar" = 4:6))
# column names with delimiters
dat <- data.frame(
A_id = 1,
A_a1 = 2,
A_a2 = "3",
B_b1 = 4,
B_b2 = 5,
B_C = 6
)
tt(dat) |> group_tt(j = "_")