So I am wondering if there is an easy way to do repeated tables / figures in quarto / rmarkdown.
for instance is there any way to use like glue or something to generate table/figure options for tables and figures that are repeated in analyses?
mtcars
mtcars_tibble <- as_tibble(mtcars, rownames = "car_name")
library('arsenal')
cols <- c('cyl', 'vs', 'am', 'gear','carb')
id = "car_name"
table_by_fun <- function(col){
renmain <- setdiff(colnames(mtcars_tibble), c(col, id))
formula1 <- as.formula(paste0(col, "~ ."))
tableby(formula1,
data = mtcars_tibble %>%
select(all_of(c(col, renmain)))
) %>%
summary(pfootnote = TRUE,
title = paste0("Univariate Analysis of ", col, " by all other predictors"))
}
table_by_fun('cyl')
purrr::map(cols, \(x){
```{r}
#| label univariate analysis of mtcars by {col}
#| tbl-cap: Univariate Analysis of {col} by all other predictors
table_by_fun(col)
```
})