Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rossellhayes opened this issue Apr 14, 2023 · 1 comment
Open
Assignees
Labels
need info Further information has been requested

Comments

@rossellhayes
Copy link
Contributor

rossellhayes commented Apr 14, 2023

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?

@rossellhayes rossellhayes added the need info Further information has been requested label Apr 14, 2023
@nischalshrestha
Copy link
Contributor

nischalshrestha commented Apr 14, 2023

This error actually occurs anytime there is a dangling final setup chunk not being used anywhere else in the tutorial:

---
title: "Tutorial with unused setup chunk"
output: learnr::tutorial
runtime: shiny_prerendered
---

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

```{r first_setup}
x <- 2
```

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

will yield:

Error: Chunk 'second_setup' is not being used by any exercise or exercise setup chunk.
Please remove chunk 'second_setup' or reference 'second_setup' with `exercise.setup = 'second_setup'`

This error was initially put in place just as a safeguard that users might accidentally forget to use a setup chunk, but authors might want a warning instead to nudge them instead of totally halting rendering of document to check other things.

But, we'll need to look at these lines and that general function for chained setup chunks to verify if there are other reasons to error. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need info Further information has been requested
Projects
None yet
Development

No branches or pull requests

2 participants