answer {learnr} | R Documentation |
Question answer options
Description
Create options for users when used in question_checkbox()
and
question_radio()
learnr questions. For question_text()
and
question_numeric()
, the individual answers aren't directly presented to
students, but their values can be used in determining if the student
submitted the correct answer. For flexible feedback from checkbox, text, and
numeric questions, answer_fn()
can be used to provide a function that
evaluates the student's submission and returns a custom result.
Usage
answer(text, correct = FALSE, message = NULL, label = text)
answer_fn(fn, label = NULL)
Arguments
text |
The answer text or value; for selection-type questions this value is shown to the user. |
correct |
Logical value indicating whether the |
message |
A custom message shown when this answer is selected and when
the overall question result matches the state of this answer. For example,
the |
label |
The label shown when the option is presented to the user. |
fn |
A function used to evaluate the submitted answer. The function is
called with the student's submitted value as the first argument, so the
function should take at least one argument where the user's value will be
passed to the first argument. Inline purrr-style lambda functions
are allowed, see In the body of the function, you can perform arbitrary calculations to
decide if the submitted answer is or is not correct and to compose the
message presented to the user. To signal a final answer, call |
Value
Returns a list with the "tutorial_question_answer"
class.
Functions
-
answer()
: Create an answer option -
answer_fn()
: Evaluate the student's submission to determine correctness and to return feedback.
Examples
answer(32, correct = FALSE)
answer(42, correct = TRUE, message = "The meaning of life.")