Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use YAML data from a child .Rmd as first level heading for a pagedown document?

I would like to use child rmarkdown documents as "chapters" in my pagedown document and have the YAML options from that child document, such as title:, be used as a first level section heading. Ideally all section headings in the child .Rmd would then be changed to one level lower.

I did my best to go through the extensive and wonderful documentation of bookdown and pagedown and rmarkdown but haven't been able to figure out how to accomplish this.

Parent Rmd:

---
title: Parent Title
output: pagedown::html_paged
---

# Parent First level header

Some text.

```{r, child='child.Rmd'}

Child Rmd:

---
title: Child Title
---

# Introduction

Some child text.

Desired Result:

---
title: Parent Title
output: pagedown::html_paged
---

# Parent First level header

Some text.

# Child Title

## Introduction

Some Child text.

like image 492
bthorne Avatar asked Sep 16 '25 02:09

bthorne


1 Answers

From https://bookdown.org/yihui/bookdown/usage.html:

Each R Markdown file must start immediately with the chapter title using the first-level heading, e.g., # Chapter Title.

You might be able to hack the code to work as desired, but it would seem easier just to add your chapter titles as first-level headings, and then just increase all subsequent section headings by one level...for example with find/replace on the regexp (^#+).

like image 134
John Colby Avatar answered Sep 17 '25 19:09

John Colby