Embedding r/exam exercises in learner tutorials. r-bloggers

- Advertisement -


[This article was first published on R/exams, and kindly contributed to R-bloggers], (You can report a problem about the content of this page here) Want to share your content on R-Blogger? Click here if you have a blog, or click here if you don’t.

- Advertisement -

Introducing the new exam2learnr package to incorporate quizzes or individual questions from dynamic exercise templates into learner tutorials that can be deployed as shiny apps.

- Advertisement -

Observation

- Advertisement -

The package exam2learnr mainly provides a function of the same name, exam2learnr(). It is an interface for embedding exercises written with R/Exam into tutorials or quizzes written with the learning package.

Learner’s goal is to produce interactive tutorials in a shiny application written with R/Markdown. Tutorials can include individual questions (exercises) or quizzes (sets of exercises) as well as text, graphics and other elements that you can embed in R/Markdown. Typically, these tutorials can be used for self-paced learning instead of (summative) assessment.

The Exams2learnr() interface leverages the learner’s capabilities to dynamically insert questions/quiz from R/exam exercise templates, written in either Rmd (R/Markdown) or Rnw (R/LaTeX) format . Currently, support is available for the following types of queries:

Description R/Exam Learner Single-Choice Learner_Radio Multiple-Choice mChoice Learner_Checkbox Numeric Number Learner_Numeric Text String Learner_Text

Thus, there is no support for cloze queries, which can combine all of the above elements.

first inspiration

To quickly try out how a certain R/exam exercise is provided in a learning tutorial, there is the convenience function run_quiz(). It sets up a tutorial embedding r/exam exercises in a temporary directory and runs the tutorial directly in a shiny app. For example, the code below creates a quiz containing a randomized version of each of these exercises that is shipped with the r/exam package: CAPITAL (multiple choice), fruit (numeric), function (string/text) ). A screenshot is included below the code.

library(“exam2learnr”) run_quiz(c(“caps.rmd”, “fruit.rmd”, “function.rmd”))

Screenshot from `run_quiz()` for exercises `capitals.Rmd`, `fruit.Rmd`, and `function.Rmd`.

As such, the run_quiz() function is good for getting a first-hand feel of what’s possible with the exam2learnr package and the look and feel of the resulting shiny apps. However, for full customization, a dedicated RMD tutorial must be installed. It can then take advantage of the main exam2learnr() function to explicitly include questions/quiz, potentially with more elements and/or optimizations.

building blocks

The main function exam2learnr() can take one or more exercise templates, either as a vector or as a list, just as for other exam2xyz() interfaces. By default, it creates a single random replica from (each) exercise, converts the text to HTML, and wraps it in a suitable learner object. A tutorial_question is returned for a single exercise and a tutorial_quiz for a vector/list of exercises. These defaults can be modified and further arguments can be passed to the underlying learner function calls to question() and quiz() respectively. This allows to customize the appearance or control whether multiple attempts are allowed, or hints/solutions are shown, etc.

As a first example, we apply exam2learnr() to the string/text function exercise, which is readily available in the R/exams package. The result is represented as a learner_text object, which inherits from tutorial_question:

Qn <- exam2learnr("function.Rmd") class(qn) ## [1] "learnr_text" "tutorial_question" print(qn) ## Question: "What is the name of the R function to extract the fitted ## log-likelihood from a fitted (normalized) linear model object?" ## Type: "learnr_text" ## allow_retry: FALSE ## random_answer_order: FALSE ## Answer: ## ✔: "logLik" ## Message: ## True: "Correct!" ## Incorrect: "Incorrect" ## Message: "logLik There is an R function to extract the ## fitted log-likelihood from a fitted (generalized) linear model object. , देखें? logLik for the corresponding manual page.” ## option: ## trim: true

Next, we set up a quiz with a single-choice SwissCapital exercise and a multiple-choice Switzerland exercise contained in tutorial_quiz, represented as learner_radio and learner_checkbox objects, respectively.

qz <- exam2learnr(c("swisscapital.Rmd", "switzerland.Rmd")) class(qz) ## [1] "tutorial_quiz" print (qz) ## Quiz: "Quiz" ## ## Question: "What is the seat of the federal authorities in Switzerland ## (ie, the actual capital)?" ## Type: "learnr_radio" ## allow_retry: FALSE ## random_answer_order: FALSE ## Answer: ## X: "Zurich" ## X: "Basel" ## ✔: "Burn" ## X: "Vaduz" # #X: "Geneva" ## Message: ## Correct: "Correct!" ## Incorrect: "False" ## Message: "There is no legal capital but actual capital and the ## seat of federal officials is burned.

,

    ,

  • lame
  • ,

  • lame
  • ,

  • Truth
  • ,

  • lame
  • ,

  • lame
  • ,

## ” ## ## Question: “Which of the following statements are true about Switzerland?” ## Type: “learnr_checkbox” ## allow_retry: FALSE ## random_answer_order: FALSE ## Answer: ## X: ” The currency in Switzerland is the Euro.” ## ✔: “Italian is an official language in Switzerland.” ## ✔: “The Swiss national holiday is 1 August.” ## X: “Switzerland is part of the European Union (EU).” ## X: “Zurich is the capital of Switzerland.” ## Message: ## Correct: “Correct!” ## False: “False” ## Message: “

    ,

  • Wrong. The currency is the Swiss Franc (CHF).
  • ,

  • Truth. The official languages ​​are: German, French, Italian, Romansh.
  • ,

  • Truth. The establishment of the Swiss Confederation is traditionally dated to August 1, 1291.
  • ,

  • Wrong. Switzerland is part of the Schengen Area. But not the EU.
  • ,

  • Wrong. There is no legal capital but the de facto capital of Switzerland is Bern.
  • ,

,

If more than n = 1 random replicates are produced a standard list is returned – because the learner does not currently provide a composite object that can capture a question bank with multiple replicates. The list has one element per random replica, each of which is a list of tutorial_question objects.

If the desired format is not selected automatically, the format of the return value can also be controlled by the output argument.

tutorial with quiz

The building blocks discussed above can be used to set up a learner tutorial with a quiz based on R/exam exercise. The output in the YAML header should be Learner::Tutorial and the runtime should be shiny_prerender. Then the quiz (or “test”) can be set up as a list of exercise templates, as is done for other exams with the 2xyz() interface. Then the entire quiz is prepared in a single exam2learnr() call. Consider for illustration:

— title: “r/exam quiz” Output: learner::tutorial runtime: shiny_prerender — “ {r setup,include=FALSE} ## List of packages and various exercise libraries(“exam2learnr”) exm < - list(c("swisscapital.Rmd", "capitals.Rmd"), "deriv.Rnw", "deriv2.Rnw", "fruit.Rmd", "boxplots.Rmd", "ttest.Rmd", "function .rmd") `` ``` {r rexams_quiz, echo = FALSE, message = FALSE} exam2learnr(exm, caption = "Please solve the following exercises") ```

The demo file above is actually shipped as a supplementary file under the exam2learnr package called learningr_quiz.Rmd. Therefore, it can be run as the following command (). The screenshot below shows the first exercise (a random replica). Concrete exercises will vary in each new run() of the tutorial.

rmarkdown::run(system.file(“learnr”, “learnr_quiz.Rmd”, package = “exams2learnr”))

Screenshot from `learnr_quiz.Rmd` tutorial.

Tutorial with individual questions

To improve the appearance of R/exam exercises within the learner tutorial, for example, it may be necessary to include each question/exercise individually, placing the different exercises into separate sections (an entire quiz Instead). For example consider the following Rmd document which is provided as supplementary file Learningr_questions.Rmd:

— title: “R/Exam Question” Output: Learner::Tutorial Runtime: Shiny_Prerender — “ {R setup, include=False} library(“Exam 2 Learner”) “ ## Knowledge Quiz (single- choice) “`{r schoice1, echo = FALSE, message = FALSE} exam2learnr(“swisscapital.Rmd”, allow_retry = TRUE, false = “False, try again.”) “## Knowledge Quiz (Multiple Choice) ) “`{r mchoice2, echo = FALSE, message = FALSE} exam2learnr(“capitals.Rmd”) “`## arithmetic (numeric) “{r num3, echo = FALSE, message = FALSE} exam2learnr( ” deriv.Rnw”, allow_retry = TRUE) “` ## arithmetic (single choice) “`{r schoice4, echo = FALSE, message = FALSE} exam2learnr(“deriv2.Rnw”) “## with multiple graphic SELECT “`{r mchoice5, echo=FALSE, message=FALSE} exam2learnr(“boxplots.Rmd”) “`## R output with multiple-choice “{r mchoice6, echo=FALSE, message=FALSE} exam2learnr(“ttest.Rmd”) “` ## string question “`{r mchoice7, echo = FALSE, message = FALSE} exam2learnr(“function.Rmd”, allow_retry = TRUE) “ `

This tutorial also shows how to use some of the learner customization options such as allow_retry or false. The following () command can be used to run this tutorial. As in the previous section, each new run () of the tutorial will have different concrete exercise variations.

rmarkdown::run(system.file(“learnr”, “learnr_questions.Rmd”, package = “exams2learnr”))

Screenshot from `learnr_questions, Rmd` tutorial (exercise `deriv.Rmd`).

Screenshot from `learnr_questions.Rmd` tutorial (exercise `boxplots.Rmd`).

related



Source link

- Advertisement -

Recent Articles

Related Stories