Logo

The Data Daily

Embedding R/exams Exercises in learnr Tutorials | R-bloggers

Embedding R/exams Exercises in learnr Tutorials | R-bloggers

Embedding R/exams Exercises in learnr Tutorials
Posted on October 23, 2022 by R/exams in R bloggers | 0 Comments
[This article was first published on R/exams , and kindly contributed to R-bloggers ]. (You can report issue about the content on this page here )
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Introduction to the new exams2learnr package for including quizzes or individual questions from dynamic exercise templates into learnr tutorials which can be deployed as shiny apps.
Overview
The package exams2learnr mainly provides the function of the same name, exams2learnr(). It is an interface for embedding exercises written with R/exams in tutorials or quizzes written with the learnr package.
The goal of learnr is the creation of interactive tutorials in a shiny application written with R/Markdown. The tutorials can contain individual questions (exercises) or quizzes (sets of exercises) along with text, graphics, and other elements you can embed in R/Markdown. Usually, these tutorials can then be used for self-paced learning rather than (summative) assessment.
The exams2learnr() interface leverages learnr’s capabilities for questions/quizzes to dynamically insert (random variations) from R/exams exercise templates, either written in Rmd (R/Markdown) or Rnw (R/LaTeX) format. Currently, there is support for the following question types:
Description
string
learnr_text
Thus, there is no support, yet, for cloze questions that can combine all of the elements above.
First motivation
For quickly trying out how a certain R/exams exercise is rendered in a learnr tutorial, there is the convenience function run_quiz(). This sets up a tutorial embedding R/exams exercises in a temporary directory and directly runs the tutorial in a shiny app. For illustration, the code below creates a quiz containing one random version of each of these exercises that are shipped with the R/exams package: capitals (multiple-choice), fruit (numeric), function (string/text). A screenshot is included below the code.
library("exams2learnr") run_quiz(c("capitals.Rmd", "fruit.Rmd", "function.Rmd"))
Thus, the run_quiz() function is nice for getting a first feeling for what is possible with the exams2learnr package and for the look & feel of the resulting shiny apps. For full customization, however, a dedicated Rmd tutorial should be set up. This can then leverage the main exams2learnr() function to explicitly include questions/quizzes, potentially along with further elements and/or customizations.
Building blocks
The main function exams2learnr() can take one or more exercise templates, either as a vector or as a list, just as for other exams2xyz() interfaces. By default, this creates a single random replication from (each of) the exercise(s), converts the text to HTML, and wraps it into a suitable learnr object. For a single exercise a tutorial_question is returned and for a vector/list of exercises a tutorial_quiz. These defaults can be modified and further arguments can be passed on to the underlying learnr function calls to question() and quiz(), respectively. This allows for customizing the appearance or controlling whether multiple attempts are allowed, or whether hints/solutions are shown, etc.
As a first example, we apply exams2learnr() to the string/text function exercise, readily provided within the R/exams package. The result is represented as a learnr_text object, inheriting from tutorial_question:
qn

Images Powered by Shutterstock