Spanning labels to identify groups of rows or columns

Description

Spanning labels to identify groups of rows or columns

Usage

group_tt(x, i = NULL, j = NULL, indent = 1, ...)

Arguments

x A data frame or data table to be rendered as a table.
i A named list of row indices to group. The names of the list will be used as labels.
j A named list of column indices to group. The names of the list will be used as labels. See examples below. Note: empty labels must be a space: " ".
indent integer number of pt to use when indenting the non-labelled rows.
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.

Examples

library(tinytable)


tt(mtcars[1:10, 1:5]) |>
  group_tt(
    i = list(
      "Hello" = 3,
      "World" = 8),
    j = list(
      "Foo" = 2:3,
      "Bar" = 4:5))
tinytable_kpj71ovpjl3jiwyb9g2n
Foo Bar
mpg cyl disp hp drat
21.0 6 160.0 110 3.90
21.0 6 160.0 110 3.90
22.8 4 108.0 93 3.85
21.4 6 258.0 110 3.08
18.7 8 360.0 175 3.15
18.1 6 225.0 105 2.76
14.3 8 360.0 245 3.21
24.4 4 146.7 62 3.69
22.8 4 140.8 95 3.92
19.2 6 167.6 123 3.92
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))  
tinytable_xhcsi4b250mpmsod0pc8
mpg cyl disp hp drat wt qsec vs
21.0 6 160.0 110 3.90 2.620 16.46 0
21.0 6 160.0 110 3.90 2.875 17.02 0
22.8 4 108.0 93 3.85 2.320 18.61 1
21.4 6 258.0 110 3.08 3.215 19.44 1
18.7 8 360.0 175 3.15 3.440 17.02 0
18.1 6 225.0 105 2.76 3.460 20.22 1
14.3 8 360.0 245 3.21 3.570 15.84 0
24.4 4 146.7 62 3.69 3.190 20.00 1
22.8 4 140.8 95 3.92 3.150 22.90 1
tt(dat) |>
  group_tt(
    j = list(
      "Hamburgers" = 1:3,
      "Halloumi" = 4:5,
      "Tofu" = 7))
tinytable_34zqes5uj909941secjk
Hamburgers Halloumi Tofu
mpg cyl disp hp drat wt qsec vs
21.0 6 160.0 110 3.90 2.620 16.46 0
21.0 6 160.0 110 3.90 2.875 17.02 0
22.8 4 108.0 93 3.85 2.320 18.61 1
21.4 6 258.0 110 3.08 3.215 19.44 1
18.7 8 360.0 175 3.15 3.440 17.02 0
18.1 6 225.0 105 2.76 3.460 20.22 1
14.3 8 360.0 245 3.21 3.570 15.84 0
24.4 4 146.7 62 3.69 3.190 20.00 1
22.8 4 140.8 95 3.92 3.150 22.90 1
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))
tinytable_zv27ld5n7kkbzmlmfq92
Foo Bar
Hello World Hello
mpg cyl disp hp drat wt
21.0 6 160 110 3.90 2.620
21.0 6 160 110 3.90 2.875
22.8 4 108 93 3.85 2.320
21.4 6 258 110 3.08 3.215
18.7 8 360 175 3.15 3.440