Repeated Tables / Figures in RMarkdown / Quarto

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_tibble <- as_tibble(mtcars, rownames = "car_name")


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, "~ ."))
          data = mtcars_tibble %>% 
            select(all_of(c(col, renmain)))
          ) %>%
    summary(pfootnote = TRUE,
            title = paste0("Univariate Analysis of ", col, " by all other predictors"))


purrr::map(cols, \(x){

#| label univariate analysis of mtcars by {col}
#| tbl-cap: Univariate Analysis of {col} by all other predictors


You can have a look at child document with knitr and how to programmatically create content

These are knitr features that will work with Quarto.

Example with tabsets and gt: Create tabsets panel from R code

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.