Code exercises
Offer the code exercise feature from {learnr}.
This should match more closely with the desire of https://github.com/coatless/quarto-webr/issues/25
Sample exercise: https://github.com/rstudio/learnr/blob/aeb8144f5335a1132dbb1c0a0302fd2f3e94b875/inst/tutorials/ex-data-filter/ex-data-filter.Rmd#L236
Proposed markup:
```{webr-r}
#| label: ex01
#| exercise: true
```
```{webr-r}
#| label: ex01-solution
filter(flights, dep_time <= 600 | dep_time == 2400)
```
```{webr-r}
#| label: ex01-hint-1
# any number with a zero exponent is equal to one
NA ^ 0
```
```{webr-r}
#| label: ex01-hint-2
# unknown value or true evaluates to true
# (because if one operand of "or" is true, we can be sure the result is true)
NA | TRUE
```
```{webr-r}
#| label: ex01-hint-3
# false and unknown value evaluates to false
# (because if one operand of "and" is true, we can be sure the result is false)
FALSE & NA
```
```{webr-r}
#| label: ex01-hint-4
# this is not a logical comparison, it's a numerical calculation involving an
# unknown value, thus resulting in an unknown value
NA * 0
```
Would this feature also support rendered radio buttons for e.g. MCQs as well (as in https://nareal.github.io/naquiz/example.html)? It's easy to emulate this with code otherwise, but I'm curious since I believe learnr and webexercises also supports some of these rendered simpler html elements.
Also of interest, do you think the approach here would lend it self well to be supported in the pyodide implementation as well? I'm planning to write a textbook using R and Py and I'm excited to see the developments here =)
@joelostblom the focus would solely be on the code evaluation portion.
The MC/MS/FIB offerings from {learnr} are better left as a standalone quarto extension as the format is reusable across languages like quarto-quiz or the naquiz format you identified. Plus, for language-specific implementations like {webexercises}, these would address content specific to R. For example:
Given a seed of
<dynamic-seed>what would be the mean of the vector given by<dynamic-numbers>.
- Option 1
- Option 2
- ...
At some point, I could imagine the joining of quarto-webr/quarto-pyodide + quarto-quiz to form quarto-learn, but I'm not likely to lead that project.
This would be excellent! My use case is writing a Quarto book with learnr exercises embedded in it. Right now, I need to keep my book separate from my tutorials. It would be much nicer to put everything into a single document. In this way, students could (be forced to) answer questions as they move through the textbook.
Quarto Live now has this feature
https://r-wasm.github.io/quarto-live/exercises/exercises.html