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()orlearnr::answer_fn(), followed by optional arguments passed tolearnr::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
learnrfor a correct answer.- incorrect
Text shown by
learnrfor an incorrect answer.- try_again
Text shown by
learnrfor an incorrect retry.- allow_retry
Whether
learnrshould allow retries.- random_answer_order
Passed to
learnr::question_text().- placeholder
Placeholder text for the input.
- trim
Whether
learnrshould trim whitespace before checking.- rows, cols
Optional text area dimensions.
- options
Additional
learnrquestion options.- context
Optional context returned by
setup_learnr_tracking(). If supplied,student_id,tutorial_id, anddb_pathare read from the context unless explicitly provided.
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
)
}