Skip to content

Error if -solution chunk has an unneeded exercise.setup option #779

@rossellhayes

Description

@rossellhayes

Using an exercise.setup option in a -solution results in an error if the chunk is not referenced in the exercise.setup option of another chunk.

---
title: "Tutorial"
output: learnr::tutorial
runtime: shiny_prerendered
---

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

## Exercise 1

```{r exercise-1, exercise = TRUE}
```

```{r exercise-1-solution}
x <- 1
```

## Exercise 2

```{r exercise-2, exercise = TRUE, exercise.setup = "exercise-1-solution"}
```

```{r exercise-2-solution, exercise.setup = "exercise-1-solution"}
y <- x + 1
```

## Exercise 3

```{r exercise-3, exercise = TRUE, exercise.setup = "exercise-2-solution"}
```

```{r exercise-3-solution, exercise.setup = "exercise-2-solution"}
z <- x + y
```
rmarkdown::run("setup-chaining.Rmd")
#> processing file: setup-chaining.Rmd
#> Quitting from lines 35-36 (setup-chaining.Rmd)
#> Error: Chunk 'exercise-3-solution' is not being used by any exercise or exercise setup chunk.
#> Please remove chunk 'exercise-3-solution' or reference 'exercise-3-solution' with `exercise.setup = 'exercise-3-solution'`

Created on 2023-04-14 with reprex v2.0.2

This can cause problems for authors who are testing an unfinished exercise that uses setup chaining. They will have to remember not to add an exercise.setup option to exercise-3-solution until after they've written exercise-4.

Would it cause any issues if this threw a warning instead of an error?

Metadata

Metadata

Labels

need infoFurther information has been requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions