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

Optionally reveal (or hide) exercise solution #470

Merged
merged 15 commits into from
Jan 15, 2021

Conversation

gadenbuie
Copy link
Member

@gadenbuie gadenbuie commented Jan 12, 2021

Adds exercise.reveal_solution, which can be set in the *-solution chunk options or globally with tutorial_options() or tutorial.exercise.reveal_solution. If FALSE, the solution is not revealed to the user. The local chunk option takes precedence over the global option.

Fixes #402

Demo Tutorial
---
title: "Optionally Reveal Exercise Solution"
output: learnr::tutorial
runtime: shiny_prerendered
---

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

## Set global reveal solution option
# options(tutorial.exercise.reveal_solution = FALSE)
# tutorial_options(exercise.reveal_solution = FALSE)
```

## Intro

### Default

<!-- exercise.reveal_solution needs to be on solution chunk -->

```{r default, exercise = TRUE, exercise.reveal_solution = TRUE}
1 + 1
```

```{r default-hint-1}
# hint code 1
```

```{r default-hint-2}
# hint code 2
```

```{r default-solution}
2
```

### Always Hides Solution

```{r hide, exercise = TRUE}
1 + 1
```

```{r hide-hint-1}
# hint code 1
```

```{r hide-hint-2}
# hint code 2
```

```{r hide-solution, exercise.reveal_solution = FALSE}
2
```

### Always Shows Solution

```{r show, exercise = TRUE}
1 + 1
```

```{r show-hint-1}
# hint code 1
```

```{r show-hint-2}
# hint code 2
```

```{r show-solution, exercise.reveal_solution = TRUE}
2
```

PR task list:

  • Update NEWS
  • Add tests (if possible)
  • Update documentation with devtools::document()

@gadenbuie
Copy link
Member Author

  1. I called the option exercise.reveal_solution but I'm open to other names if there are any suggestions.
  2. Unlike the other exercise options that are set on the exercise chunk, this option needs to be set on the *-solution chunk. I'm okay with that, since it's only relevant to the solution, but I thought I'd bring it up.
  3. I'm not sure how to test this feature. learnr suggests shinytest but doesn't seem to use it in the test suite. Would this be a good use case for shinytest?

The errors are still surfaced by render() and the test should be runnable on CRAN.

I included a skip if pandoc isn't available, since if the knit step is successful, pandoc will be called.

This also protects against tests where rmarkdown::run() should fail but doesnt, in which case run() will launch the tutorial and run indefinitely.
Copy link
Collaborator

@schloerke schloerke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM given minor changes

NEWS.md Outdated Show resolved Hide resolved
R/knitr-hooks.R Show resolved Hide resolved
R/knitr-hooks.R Outdated Show resolved Hide resolved
docs/exercises.Rmd Outdated Show resolved Hide resolved
tests/testthat/test-options-reveal_solution.R Show resolved Hide resolved
@schloerke
Copy link
Collaborator

schloerke commented Jan 13, 2021

  1. I like exercise.reveal_solution
  2. See Optionally reveal (or hide) exercise solution #470 (comment)
  3. (addressed)

NEWS.md Outdated Show resolved Hide resolved
R/knitr-hooks.R Outdated Show resolved Hide resolved
@gadenbuie gadenbuie merged commit b36e840 into rstudio:master Jan 15, 2021
@gadenbuie gadenbuie deleted the optionally-reveal-solution branch January 15, 2021 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Global option to show/hide solution
2 participants