I wrote a series of learnr tutorials to help students learn R, and I need to record when students have submitted an answer to a question or an exercise. A section of the learnr documentation touches on this topic (https://rstudio.github.io/learnr/publishing.html#recording_events), but not at the level of detail I need, apparently. I have two main question areas, and below those I've pasted code for a sample tutorial.
Setting the
tutorial.event_recorderoption: Thelearnrdocumentation states"You can capture events by using a custom event recorder function. This function is specified via the
tutorial.event_recorderglobal option."I found one example online where this is defined in the setup chunk as
options(tutorial.event_recorder = learnr:::debug_event_recorder)So that's what I've put in my code, but are there other possible options? Am I even using it correctly?
Actually recording events: the
learnrdocumentation creates an example event recorder function printing to stdout astutorial_event_recorder <- function(tutorial_id, tutorial_version, user_id, event, data) { cat(tutorial_id, " (", tutorial_version, "): ", user_id , "\n", sep = "") cat("event: ", event, "\n", sep = "") }
Let's say I was happy with that level of event recording: I'm assuming I define it in some R code chunk, but where do I call it? Are tutorial_id, tutorial_version, and user_id global arguments that are defined by the program once I set the tutorial.event_recorder option? Then do I define the event as exercise_submission, for example? Is there an argument that specifies which exercise or question was submitted? I typically have several exercises and questions per tutorial.
I have pasted an example of my tutorial code if this helps. Eventually I would like to incorporate the checkr package and its event recording, but I don't have time to do that well at the moment. The tutorials are hosted on a server but I am first trying just to get event recording to work locally. Thank you very much!
---
title: "Tutorial: Categorical Variables"
output: learnr::tutorial
runtime: shiny_prerendered
tutorial:
id: "toytorial"
---
```{r setup, include=FALSE}
library(learnr)
knitr::opts_chunk$set(echo = TRUE)
tutorial_options(exercise.eval = FALSE)
options(tutorial.event_recorder = learnr:::debug_event_recorder)
```
### Test yourself
Use the `dim()` command to get the number of columns and rows in the data frame 'iris'.
```{r, ex1, exercise=TRUE, echo = FALSE}
```
```{r, q1, echo=FALSE}
question("How many rows are in the 'iris' data frame?",
answer("5"),
answer("150", correct=TRUE)
)
```
EDIT: After Andrie's answer on 8/24 and the helpful sample tutorial Andrie posted at github.com/rstudio/learnr/issues/182 I have updated my setup chunk in my sample tutorial to:
```{r setup, include=FALSE}
library(learnr)
knitr::opts_chunk$set(echo = TRUE)
tutorial_options(exercise.eval = FALSE)
new_recorder <- function(tutorial_id, tutorial_version, user_id, event, data) {
cat(tutorial_id, " (", tutorial_version, "): ", user_id, ", ", event, ", ", data$label, ", ", data$answers, ", ", data$correct, "\n", sep = "")
}
options(tutorial.event_recorder = new_recorder)
```
Now that I know to look at the R Markdown window in RStudio I see the recording as questions are answered or exercises attempted. I still cannot figure out how to write the event recording to a file or database: sink() doesn't seem to work for me.