I am trying to create a function that outputs a kbl object. I would like to be able to pass arguments in the function call for both kbl() and kable_styling() to fine-tune the table as required for a specific dataset. I can get it to work using ... for one of the functions but not both.
library(kableExtra)
table_fun <- function(x, format_f = "latex", ...) {
kbl(x,
digits = 2,
align = NULL, # default numeric columns are right-aligned, and other columns are left-aligned
format.args = list(decimal.mark = '.', big.mark = " "),
booktabs = TRUE,
format = format_f,
escape = FALSE,
...) %>% # this does not allow for any additional arguments to be passed
kable_styling(latex_options = c("hold_position"),
full_width = F,
protect_latex = TRUE,
...)
}
table_fun(iris,
format_f = "html", # for this example
caption = "This is a table", # argument in kbl(); error thrown
font_size = 20) # argument in kable_styling()
>> Error in kable_styling(., latex_options = c("hold_position"), full_width = F, :
unused argument (caption = "caption")
So I change the font size in kable_styling(), but I can't change the caption in kbl(). How would I go about fixing this function? Thanks!