Skip to contents

Wraps learnr::question_text() and records each submitted answer in a learnrTrackR SQLite database when learnr evaluates the question.

Usage

tracked_question_text(
  text,
  ...,
  question_id,
  tutorial_id,
  student_id,
  db_path,
  max_score = 1,
  correct = "Correct!",
  incorrect = "Incorrect",
  try_again = incorrect,
  allow_retry = FALSE,
  random_answer_order = FALSE,
  placeholder = "Enter answer here...",
  trim = TRUE,
  rows = NULL,
  cols = NULL,
  options = list(),
  context = NULL
)

Arguments

text

Question text passed to learnr::question_text().

...

Answers created with learnr::answer() or learnr::answer_fn(), followed by optional arguments passed to learnr::question_text().

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.

correct

Text shown by learnr for a correct answer.

incorrect

Text shown by learnr for an incorrect answer.

try_again

Text shown by learnr for an incorrect retry.

allow_retry

Whether learnr should allow retries.

random_answer_order

Passed to learnr::question_text().

placeholder

Placeholder text for the input.

trim

Whether learnr should trim whitespace before checking.

rows, cols

Optional text area dimensions.

options

Additional learnr question options.

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 learnr text question object with tracking metadata.

Details

The tracking implementation uses the public learnr::question_is_correct() S3 extension point. It does not use browser JavaScript interception.

Examples

if (requireNamespace("learnr", quietly = TRUE)) {
  db_path <- tempfile(fileext = ".sqlite")
  question <- tracked_question_text(
    "Type the word mean.",
    learnr::answer("mean", correct = TRUE),
    question_id = "q1",
    tutorial_id = "module_01",
    student_id = "student_001",
    db_path = db_path
  )
}