'In learnr can you have exercise chunks with incorrect code?

I'm writing a learnr course, I want to provide students with faulty code for them to fix, or demonstrate an error. For example:

---
title: "coding - intro"
output:
  learnr::tutorial:
    progressive: true
    allow_skip: true
runtime: shiny_prerendered
---

```{r setup, include=FALSE}
library(learnr)
```


```{r code_intro_data_type_error, exercise = FALSE, exercise.eval = FALSE}
weeks <- 4
days_in_week <- "7"

# we now attempt to multiple a number by a string
total_days <- weeks * days_in_week
```

I'd ideally also like to output the error message:

Error in weeks * days_in_week : non-numeric argument to binary operator

But because the code has an error in that chunk it refuses to compile the learnr script



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source