Grading with {gradethis}

Grade solutions to R exercises using the existing {gradethis} R package

Setup

The quarto-live extension must be configured to use the {gradethis} R package in grading algorithms. Include the following lines after the document YAML header, but before your main content, in your Quarto document:

{{< include ./_extensions/r-wasm/live/_knitr.qmd >}}
{{< include ./_extensions/r-wasm/live/_gradethis.qmd >}}
Note

This configuration step is temporary. It is planned in a future version of quarto-live to be configurable by a key in the document YAML header instead.

Grading with a template solution

First, create a webr exercise as normal,

gradethis.qmd
```{webr}
#| exercise: ex_1
#| setup: true
library(dplyr)
```

```{webr}
#| caption: Sample Exercise
#| exercise: ex_1
starwars |> ______
```

Next, create a solution block for your exercise. Ensure that some template solution code is given in the form of a webr code block, linked to your exercise and with the cell option solution: true set.

gradethis.qmd
::: {.solution exercise="ex_1"}

#### Solution

Use the `distinct()` function from the `{dplyr}` package.

```{webr}
#| exercise: ex_1
#| solution: true
starwars |> distinct(hair_color)
```

:::

Finally, create grading algorithm using {gradethis} package by adding a webr code block with the cell option check: true set. The grading algorithm should call gradethis::grade_this_code().

The template code provided in your solution block will be compared to the user provided code to automatically generate relevant feedback.

gradethis.qmd
```{webr}
#| exercise: ex_1
#| check: true
gradethis::grade_this_code()
```

Output

Solution:

starwars |> distinct(hair_color)
starwars |> distinct(hair_color)