Make use of the knitr::knit_child()
call in your function:
---
title: "Untitled"
date: "10/9/2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
full_var <- function(var) {
cat("### ", var, "{-}", "\n")
cat("\n")
child <- knitr::knit_child(paste0(var, ".Rmd"), quiet = TRUE)
cat(child, sep = "\n")
}
vars <- c("1", "2", "3")
```
```{r results = "asis"}
purrr::walk(vars, full_var)
```
This should read your child .Rmd files, provided, of course, that they are located in your working directory.