gradethis icon indicating copy to clipboard operation
gradethis copied to clipboard

`grade_this_code()` produces error in `-code-check` (but `grade_code()` succeeds)

Open gcpoole opened this issue 1 year ago • 1 comments

The help file for grade_this_code() states the following:

If grade_this_code() is called in a -code-check chunk and returns feedback, either passing or failing feedback, then the user's code is not executed. If you want the user to see the output of their code, call grade_this_code() in the -check chunk.

  • When I call grade_this_code() in a -check chuck, it works as expected when an exercise is submitted.
  • If I change the -check chunk into a -code-check chunk, the tutorial raises an error: "A problem occurred with the grading code for this exercise" when an exercise is submitted.
  • If I change grade_this_code() to grade_code() in the -code-check chunk, everything works as expected when an exercise is submitted, but grade-code() is tagged as superseded by grade_this_code()

learnr: version 0.11.5.9000 gradethis: version 0.2.14

Here is a reproducible example:

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

```{r setup, include=FALSE}
library(learnr)
knitr::opts_chunk$set(echo = FALSE)
gradethis::gradethis_setup()
```

## Topic 1

Write the R code required to add two plus two:

```{r two-plus-two, exercise=TRUE}

```

```{r two-plus-two-solution}
2+2
```

<!-- The following works fine: note `-check` chunk with `grade_this_code()`

```{r two-plus-two-check}
gradethis::grade_this_code()
```
-->

<!-- The following works fine: note `-code-check` chunk with `grade_code()`

```{r two-plus-two-code-check}
gradethis::grade_code()
```
-->

<!-- the following fails with an error: `-code-check` chunk with `grade_this_code() -->

```{r two-plus-two-code-check}
gradethis::grade_this_code()
```

gcpoole avatar Jan 13 '24 21:01 gcpoole

Issue was confirmed on stack overflow prior to report: https://stackoverflow.com/questions/77809420/bug-gradethisgrade-this-code-fails-in-code-check-chunk

gcpoole avatar Jan 13 '24 21:01 gcpoole