knitr::knit_child with Quarto

Quarto is the new publishing system from RStudio based on Pandoc. It's a powerful tool for publising from R, Python and Julia, working in a very similar fashion to RMarkdown.
There are several great blog posts already highlighting features of Quarto and thoughts on changing from RMarkdown to Quarto.

Recently, I've been building up dynamic documents using child documents. The aim is to identify the parts of a document (report) required and compile them into a main report as child documents. I've also started to use Quarto, but can Quarto build a document from a selection of child docs? The answer is 'yes'.

RMarkdown Version

knitr Child documents are a great way to manage long reports. They provide a method to break a document into sections and knit the sections together upon rendering. Below we have a main Rmd document and a child Rmd document. When rendered, the child document is incorporated into the main document.

Main Document

 1---
 2title: "Child docs (RMarkdown)"
 3output: html_document
 4---
 5
 6Test quarto document using child docs - RMarkdown verion
 7
 8```{r, include=FALSE}
 9library(knitr)
10```
11
12```{r, results='asis', echo=FALSE}
13a <- knitr::knit_child('child_doc_01.Rmd', quiet=T)
14cat(a, sep='\n')
15```

Child Document 1 (child_doc_01.Rmd)

1---
2tag: "my child 01"
3title: "child doc 01"
4---
5
6## Child Doc 1
7
8Child document #1 - this is an RMarkdown child document

Output

Quarto Version

Quarto child documents can be knitted in the same way as RMarkdown documents, using knitr::knit_child. In fact Quarto and RMarkdown child documents can be mixed as shown below.

Main Document

 1---
 2title: "Child docs"
 3format: html
 4execute: 
 5  echo: false
 6self-contained: true
 7---
 8
 9Quarto child documents are compatible with knitr::knit_child
10
11```{r}
12#| include: false
13library(knitr)
14```
15
16```{r, results='asis'}
17a <- knitr::knit_child('child_doc_01.Rmd', quiet=T)
18cat(a, sep="\n")
19```
20
21```{r, results='asis'}
22a <- knitr::knit_child('child_doc_02.qmd', quiet=T)
23cat(a, sep="\n")
24```

Child Document 2 (child_doc_02.qmd)

 1---
 2title: "Untitled"
 3format: html
 4---
 5
 6## Child Doc 2
 7
 8Child document #2 - this is a quarto child document running {ojs} cell
 9
10```{r}
11ojs_define(data = mtcars)
12```
13
14```{ojs}
15Plot.plot({
16  marks: [
17    Plot.dot(transpose(data), 
18      {x: "mpg", y: "hp", stroke: "cyl"}
19    )
20  ]}
21)
22```

Output