Put Errors in Code Chunks for Students to find and fix, but will not knit

I would like to include a code block with an error

ggplot(Indometh, x= time, y = conc) + 
  geom_smooth() +
  geom_point() +
  labs(title = "Indomethacin Concentration Over Time \n After a Single Oral Dose",
       x = "Time in Hours",
       y = "Concentration in \U00B5g/mL")

and ask the students to interpret the error message (with help from Google), find the error, and fix it.

With the error in place, the Rmd will not knit.

While I could comment out the code, and ask them to remove the hashtags and run it, is there a way to ignore code chunk errors when knitting?

error = FALSE does not seem to do the trick.

You tried just the opposite. Try error = TRUE.

See the following document:

R Markdown File
---
title: "Preserve Error"
output: html_document
---

Bla Bla Bla

```{r error=TRUE}
library(ggplot2)

ggplot(Indometh, x= time, y = conc) + 
  geom_smooth() +
  geom_point() +
  labs(title = "Indomethacin Concentration Over Time \n After a Single Oral Dose",
       x = "Time in Hours",
       y = "Concentration in \U00B5g/mL")
```

Bla Bla Bla

It leads to:

2 Likes

Thanks for the help.
I must say, the logic seems backwards, given the exemplars of
include = FALSE
message = FALSE
warning = FALSE.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.