3

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

Joe
  • 3,217
  • 3
  • 21
  • 37
  • 2
    The problem is that there is a space after `---` if you remove the space, everything should work as expected. – DaveArmstrong Jan 04 '22 at 23:58
  • Indeed that was the problem! – Joe Jan 05 '22 at 00:00
  • I just love semantically significant whitespace. Ugh. – Ben Bolker Jan 05 '22 at 00:03
  • 1
    @DaveArmstrong, post as answer? (I don't think I'd close this as "due to a typo", as it could indeed be a useful answer for other people) – Ben Bolker Jan 05 '22 at 00:03
  • When you want to insert a horizontal rule into the slide, you would need the trailing space. The slide separator must be strictly three dashes without spaces. There needs to be a way for remark.js to differentiate between the separator and the rule. More info: https://yihui.org/en/2018/07/yue-jiang/ – Yihui Xie Jan 06 '22 at 04:05

1 Answers1

2

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.

DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25