I have a quarto file metav1.qmd. It needs to contain many child files such as child1.qmd, child2.qmd,..., child100.qmd. All child files need to be condionally included in metav1.qmd.
For example, uncoditonally including child1.qmd (this is included in quarto document):
{{< include child1.qmd >}}
How to make it conditional? I tried the following:
temp_file <- "include_temp1.qmd"
child1<-max(nrow(data1),nrow(data2))
if (child1) {
writeLines("{{< include child1.qmd >}}", con = temp_file)
} else {writeLines("", con = temp_file)}
{{< include include_temp1.qmd >}}
unlink("include_temp1.qmd")
I ran above code to let Quarto conditionally include the child file child1.qmd, however, Quarto does not allow to create a temporary file inlcude_temp.qmd. This made above code practically not feasible as we need to run the code again and again but it won't let us to update the temporary file after unlink(). But abvoe code can create include_temp1.qmd when run it in R console.
I alos run the following
{{ h#if child1}}
{{< include include_temp1.qmd >}}
{{/if}
It does not run the condition head {{h#if child1}} and condition end {{/if} but only run {{< include include_temp1.qmd >}}. Here, "h" in front of hash sign# should be removed when run this code and I added it here for showing the hash sign# purpose
I tried
{r childchunk, if(child1){"child1.qmd"}}
It does not work since {r childchunk, if(child1){"child1.qmd"}} is an R Markdown command but RMarkdown does not compartible with Quarto since R Markdown is earlier than Quarto.
In summary, how to let Quarto to conditonally include child file? how to let Quarto to create .qmd file in the main .qmd file?