global arguments in rmarkdown

I've recently started using R Markdown and I'm beginning to understand the concept of chunk options vs. global options with knitr::opts_chunk$set. Initially I assumed this ment I could set global arguments to functions that I repeatedly use, but this can't be correct?

The main question:
I'm using kableExtra for my tables, and I have a bunch of them. Is there a way to set global arguments instead of options? E.g I'd like bootstrap_options = c("striped", "condensed") every time I use kable_styling().

Is there a way to set global arguments instead of options? E.g I'd like bootstrap_options = c("striped", "condensed") every time I use kable_styling() .

Not in the way you suggest. But you could overwrite the kable_styling() function, e.g.

# Change arguments to what you want
kable_styling = kableExtra::kable_styling(kable_input, bootstrap_options = "basic",
  latex_options = "basic", full_width = NULL, position = "center",
  font_size = NULL, row_label_position = "l", ...)

Then whenever you call kable_styling() you are calling your version that is a thin wrapper around the original.

If you end up creating a few of these functions, consider putting them in a package.

4 Likes

Thank you! Kind of obvious now that you mention it:)

Just noting that I had to declare the function a la:

kable_styling2 = function(kable_input)
  kable_styling(
    kable_input,
    bootstrap_options = c("hover","striped"),
    full_width = F, position = "center",
    font_size = 11)