I'm trying to use knitr::kable
in order to build a nice-looking table with several levels of grouping. I've been successful with most of my work but I need to define several groups of rows and I thought that the function kableExtra::group_rows
was exactly what I would need. There is some pretty good documentation out there (https://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf) with some easy-to-follow examples regarding the use of this function, but I seem unable to reproduce the output being shown.
Here's the code snippet from the above linked documentation demonstrating the use of the function.
However, the exact same code in my interactive session does not group the rows:
kable(mtcars[1:10, 1:6], caption = "Group Rows", booktabs = T) %>%
kable_styling() %>%
group_rows("Group 1", 4, 7) %>%
group_rows("Group 2", 8, 10)
| | mpg| cyl| disp| hp| drat| wt|
|:-----------------|----:|---:|-----:|---:|----:|-----:|
|Mazda RX4 | 21.0| 6| 160.0| 110| 3.90| 2.620|
|Mazda RX4 Wag | 21.0| 6| 160.0| 110| 3.90| 2.875|
|Datsun 710 | 22.8| 4| 108.0| 93| 3.85| 2.320|
|Hornet 4 Drive | 21.4| 6| 258.0| 110| 3.08| 3.215|
|Hornet Sportabout | 18.7| 8| 360.0| 175| 3.15| 3.440|
|Valiant | 18.1| 6| 225.0| 105| 2.76| 3.460|
|Duster 360 | 14.3| 8| 360.0| 245| 3.21| 3.570|
|Merc 240D | 24.4| 4| 146.7| 62| 3.69| 3.190|
|Merc 230 | 22.8| 4| 140.8| 95| 3.92| 3.150|
|Merc 280 | 19.2| 6| 167.6| 123| 3.92| 3.440|
As far as I can tell, the group_rows
functions are completely ignored. I've tried this by using the format = "latex"
option to produce the raw latex and this has been similarly unsuccessful. I'm starting to wonder if this function isn't deprecated? A similar question saw some issues using it with special escape characters but I don't seem to be able to make it work even with simple data.