knitr::include_graphics() disables slide break operator (---) in xaringan

Viewed 48

When I include an image in a xaringan deck using knitr::include_graphics(), my page break operator (---) fails, and the next slide merges into the previous slide.

Here is a reprex demonstrating the problem:

---
title: "knitr::include_graphics() disables slide break operator (---)"
date: "2022-01-04"
output: xaringan::moon_reader
---

# This slide break will work

---

# But when my slide has an image, the slide break will fail

```{r out.width='30%'}
knitr::include_graphics("hp.jpg")
```

--- 

# This should have been a new slide

```{r out.width='30%'}
knitr::include_graphics("hp.jpg")
```

enter image description here

1 Answers

The problem is a that xaringan is very picky about what page breaks look like. In the example above, there is a whitespace after the second --- which is causing the problem. Removing he whitespace will fix the error.

Related