How can I get a printed error message in RMarkdown to collapse into a single block when the error message itself was modified to print in red?
In this example collapse = T
works as expected.
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, collapse = TRUE)
```
```{r error=T}
x <- c(1,2,3,4,5)
x * 10
X * 10
```
In this example, I modified the error message to be formatted in red (based on this answer). But then it doesn't collapse with the rest:
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, collapse = TRUE)
knitr::knit_hooks$set(error = function(x, options) {
paste0("<pre style=\"color: red;\"><code>", x, "</code></pre>")
})
```
```{r error=T}
x <- c(1,2,3,4,5)
x * 10
X * 10
```
I tried to specify collapse = T
again in the specific code chunk but this won't work either:
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, collapse = TRUE)
knitr::knit_hooks$set(error = function(x, options) {
paste0("<pre style=\"color: red;\"><code>", x, "</code></pre>")
})
```
```{r error=T, collapse = T}
x <- c(1,2,3,4,5)
x * 10
X * 10
```