We can use the standard which function from Base R to create indices and apply conditional stying on rows. And we can use a regular expression in j to apply conditional styling on columns:
The i argument accepts a named list of integers. The numbers identify the positions where row group labels are to be inserted. The names includes the text that should be inserted:
-
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))
+
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))
The syntax for column groups is very similar, but we use the j argument instead. The named list specifies the labels to appear in column-spanning labels, and the values must be a vector of consecutive and non-overlapping integers that indicate which columns are associated to which labels:
The Bootstrap framework provides a number of built-in themes to style tables. To use them, we call bootstrapOptions() with the class argument, and we specify the Bootstrap class. A list of available Bootstrap classes can be found here: https://getbootstrap.com/docs/5.3/content/tables/
For example, to produce a “dark” table, we use the table-dark class:
For more extensive customization, we can use complete CSS rules. In this example, we define several rules that apply to a new class called mytable. Then, we use the theme argument of the tt() function to ensure that our tiny table is of class mytable. Finally, we call style_bootstrap() to apply the rules with the bootstrap_css_rule argument.