How to include an unmatched ']' within a Rmarkdown Xaringan code chunk?

Viewed 38

I stumbled upon a weird issue that is breaking my xaringan presentation: Apparently the including an unmatched "]" within a string in a code chunk is being interpreted as closing a css-class specifier and thus closes the code chunk prematurely.

Here is a minimal example of the problem - in my case the code chunk in the right column of slide 2 does not render correctly and interferes with the column definition itself.

---
title: "Xaringan wtf ']'?"
output:
  xaringan::moon_reader:
    lib_dir: libs
---

```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```

.pull-left[
works nicely
```{r}
cat("test")
```
]

.pull-right[
breaks
```{r}
cat('test]')
```
]

Has anyone else encountered this before and knows a solution to this issue?

(In case anyone wonders what this is for: I want to be able to address the levels created by cut() - eg cut(1:5,breaks = c(0,2,5)))

0 Answers
Related