Render a question which asks the user to input a value. Questions of numeric support auto-grading.
text_question( title, points = 1, type = c("textarea", "text", "numeric"), width = "100%", height = NULL, placeholder = NULL, solution = NULL, solution_quoted = FALSE, comp = comp_digits(3, 1), label = "Type your answer below.", hide_label = FALSE, mandatory = FALSE, id = NULL, title_container = h6, static_title = NULL ) comp_abs(tol) comp_rel(tol) comp_digits(digits, pm = 1)
title | question title. Markdown is supported and by default the title will be rendered dynamically if it contains inline R code. |
---|---|
points | total number of points for the question. Set to |
type | can be one of |
width | the width of the input, e.g., '300px' or '100%'; see |
height | the height of the input, e.g., '300px' or '100%'; see |
placeholder | A character string giving the user a hint as to what can be entered into the control. Internet Explorer 8 and 9 do not support this option. |
solution | an expression to compute the solution to the answer.
The expression is evaluated in the environment returned by the data provider set up via |
solution_quoted | is the |
comp | function comparing the user's input with the correct answer. Must be a function taking two
named arguments: |
label | a label to help screen readers describe the purpose of the input element. |
hide_label | hide the label from non-screen readers. |
mandatory | is this question mandatory for submitting the section? If |
id | question identifier to be used instead of the code chunk label. Must only contain
characters |
title_container | a function to generate an HTML element to contain the question title. |
static_title | if |
tol | absolute tolerance (for |
digits | number of digits relevant for comparison (significant digits if the correct answer is less than 1 in absolute value). |
pm | amount by how much the last (significant) digit may vary between the user's input and the correct answer. |
The solution is computed by evaluating the expression given in solution
in the rendering environment.
The expression must yield either a single character string or, if the question is of type numeric, a numeric value.
The result of the expression is rendered with commonmark.
To auto-grade numeric questions, the solution
expression can yield a numeric value or a character value with
attribute answer
. This number is compared against the user's answer using the function provided via comp
.
comp_abs
: compare the user input and the correct answer in absolute terms
(returns abs(input - answer) < tol
).
comp_rel
: compare the user input and the correct answer in relative terms
(returns abs(input / answer - 1) < tol
).
comp_digits
: allow the last digit vary by +/- pm
. For answers greater than 1 (in absolute value),
digits
is the number of digits after the decimal point and an absolute tolerance of
of tol = pm * 10^-digits
is used.
For answers less than 1, digits
is the number of significant digits and an
absolute tolerance of tol = pm * 10^(-shift)
is used (shift
is taken such that
the last sign. digit can vary by +/- pm
). Returns abs(input - answer) < tol
).
Other exam question types:
mc_question()