Skip to contents

Creates a tracked learnr question and dispatches to the appropriate question-specific helper: tracked_question_radio(), tracked_question_checkbox(), tracked_question_text(), or tracked_question_numeric().

Usage

tracked_question(
  text,
  ...,
  type = c("auto", "single", "multiple", "radio", "checkbox", "text", "numeric",
    "learnr_radio", "learnr_checkbox", "learnr_text", "learnr_numeric"),
  question_id,
  tutorial_id,
  student_id,
  db_path,
  max_score = 1,
  context = NULL
)

Arguments

text

Question text.

...

Answers and type-specific arguments passed to the selected question helper.

type

Question type. Supported values are "auto", "radio", "checkbox", "text", and "numeric", with aliases "single", "multiple", "learnr_radio", "learnr_checkbox", "learnr_text", and "learnr_numeric".

question_id

Question identifier stored in the tracking database.

tutorial_id

Tutorial identifier stored in the tracking database.

student_id

Student identifier stored in the tracking database.

db_path

Path to the SQLite tracking database.

max_score

Maximum score stored for the question. Defaults to 1.

context

Optional context returned by setup_learnr_tracking(). If supplied, student_id, tutorial_id, and db_path are read from the context unless explicitly provided.

Value

A tracked learnr question object.

Details

For type = "auto", the helper follows the same simple convention as learnr::question() for literal answer choices: one correct answer creates a radio question, and more than one correct answer creates a checkbox question. Text and numeric questions should be requested explicitly with type = "text" or type = "numeric".

Examples

if (requireNamespace("learnr", quietly = TRUE)) {
  db_path <- tempfile(fileext = ".sqlite")
  question <- tracked_question(
    "What is 2 + 2?",
    learnr::answer("3"),
    learnr::answer("4", correct = TRUE),
    type = "radio",
    question_id = "q1",
    tutorial_id = "module_01",
    student_id = "student_001",
    db_path = db_path
  )

  tracking <- setup_learnr_tracking(
    tutorial_id = "module_01",
    student_id = "student_001",
    db_path = db_path
  )

  tracked_question(
    "What is 3 + 3?",
    learnr::answer("5"),
    learnr::answer("6", correct = TRUE),
    type = "radio",
    question_id = "q2",
    context = tracking
  )
}
#> Question: "What is 3 + 3?"
#>   type: "learnr_radio"
#>   allow_retry: FALSE
#>   random_answer_order: FALSE
#>   answers:
#>     X: "5"
#>     ✔: "6"
#>   messages:
#>     correct: "Correct!"
#>     incorrect: "Incorrect"
#>   Options:
#> c("    learnrTrackR: student_001", "    learnrTrackR: module_01", "    learnrTrackR: q2", "    learnrTrackR: /tmp/Rtmpktuqs0/file19a63955f61f.sqlite", "    learnrTrackR: 1")