kableExtra: Specify the look of selected rows programatically

1.3k views Asked by At

Currently kableExtra 0.5.1 only supports Specify the look of the selected row. I wonder if there is any tweak to specify the look of selected rows programatically like row_spec(x, c(1, 3, 4), bold = TRUE, italic = TRUE). Thanks

library(knitr)
library(kableExtra)

x <- knitr::kable(head(mtcars), "latex")
kableExtra::row_spec(x, 1, bold = TRUE, italic = TRUE)
1

There are 1 answers

2
user2554330 On BEST ANSWER

You can do it in a loop.

multirow_spec <- function(x, rows, ...) {
  for (row in rows) 
    x <- kableExtra::row_spec(x, row, ...)
  x
}

x <- knitr::kable(head(mtcars), "latex")
multirow_spec(x, c(1, 3, 4), bold = TRUE, italic = TRUE)