RFen
RFen

Reputation: 161

Can I generate separate HTML file for each header using rmarkdown::render()?

I generate reports using rmarkdown::render() function on a list of .Rmd files and I get one HTML file for each of them.

That was fine until my dataset got bigger and my reports now contain >100 figures... The HTML files often end-up being >100MB and I now have some very big ones (~500MB).

The .Rmd is separated in several chunks so one might think I have to split my .Rmd in smaller files (let's say one chunk per file). This is not (easily) doable because the .Rmd defines a data-processing workflow (figures generated in chunk3 require processings made in chunk1 and chunk2).

I would like to know if it is possible to split the rendering in several HTML files automatically. Ideally I dream about a 'splitHeader' argument in render() that would generate separate HTML file for each header of a specified level.

I guess an ugly solution is to manually add conditional statements for every chunk/header that I would like rendered (or not), and call render() several time with different arguments. But this is extremely inefficient (and ugly, I said that already)...

Would somebody have suggestions to achieve that ?

Upvotes: 2

Views: 417

Answers (1)

Orlando Sabogal
Orlando Sabogal

Reputation: 1640

I am not sure if this solve (or at least help to solve): You can have multiple independent .Rmd files (childs) dividing the content as you like. In a "Mother" file, you can add the child using:

```{r child = "yourChild.Rmd"}
```

The child .Rmd files should no contain any header information. That is, delete the first lines in you .Rmd that are something like:

---
title: "Your Title"
author: "Your name"
output: html_notebook
---   

Upvotes: 1

Related Questions