0

I am building a dashboard in Flexdashboard (based on R Markdown), which will eventually have many (around 50) pages, so would be very unwieldly in one file. To cope with this, I have decided to break it down into separate files – possibly each with their own ‘children’. To save writing file names in manually and having to update each time a new page is added, I followed the advice in this answer – getting R to automate the generation of

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

chunks, based on the .Rmd files stored in a specified folder.

A minimum reproducible example of the code I am using is:

```{r}
rmd_files_for_dashboard <- list.files(path = "subfolder_containing_files/", pattern = '*.Rmd', recursive = T) # Picks out the filenames of .Rmd files to be included in the dashboard
chunks <- paste0("```{r child = 'subfolder_containing_files /", data_collections_rmd_files, "'}\n```\n")  # Puts together the ```{r child = 'file_name.Rmd'} ``` chunks
cat(chunks, sep = '\n') # Combines these chunks and runs them in R.
```

Where subfolder_containing_files is a subfolder of my working directory, containing multiple .Rmd files to be added to the dashboard. I’ll call the above code ‘A’, for brevity.

Code A is not working for me. I can copy the output of running the code (I’ll call this output ‘B’) into my R markdown file, then it works perfectly, but if I paste code A itself into the markdown file, these pages don’t appear in the dashboard.

Comparing the HTML output of both these cases, the problem seems to be to do with apostrophes. When code B is pasted directly into the markdown file, a series of HTML tags appear, containing the contents of the markdown files knitted together into HTML. However when I paste code A into the markdown file, the resulting HTML contains:

<pre><code>```{r child = &#39;subfolder_containing_files/Page_1.Rmd&#39;}
<div id="page-1" class="section level1">
```
<h1>Page 1</h1>
<p>Page 1 text</p>
```{r child = &#39;subfolder_containing_files/Page_2.Rmd&#39;}
</div>
```</code></pre>

This code is adapted from my original file, to remove identifiable information. It seems that apostrophes are not being produced properly?

Strangely, in running code for a minimum reproducible example, I encountered a slightly different issue - with the HTML from code A containing:

which isn’t found in the output from code B. Code A's output still contained several ' though, so I imagine the solution will be the same?

Either way, the same issue is that code A does not appear to work. With 2 files, it’s fine to do it manually, but with 50, it would be too much work!

Can you help? Thank you!

whv20
  • 149
  • 7
  • In the code chunk that outputs everything. You might want to add the chunk option `results = 'asis'` – Jamie Aug 11 '23 at 14:24

0 Answers0