This function is a wrapper that creates the appropriate answer object based on the input. It can handle multiple choice questions, true/false questions, short answer questions, numerical questions (with exact answers, precision-based answers, or range-based answers), and matching questions. The function will automatically determine the type of question based on the format of the input and create the corresponding answer object using the appropriate helper functions.
Arguments
- x
The correct answer(s) for the question. See details for the expected format based on the type of question.
- y
Additional parameter for certain question types. See details for the expected format based on the type of question.
- tol
The acceptable error margin for the answer. Defaults to 0 for an exact answer.
- precision
The number of decimal places the answer must be correct to.
Details
The function uses the following logic to determine the type of question:
If
xis a logical value andyis NULL, it creates a true/false question usinganswer_true_false().If
xis a single numeric value andyis NULL, it creates a numerical question with an exact answer usinganswer_num(). Iftolis greater than 0, it creates a numerical question with an error margin. Ifprecisionis greater than 0, it creates a numerical question with a specified precision.If
xis a numeric vector of length 2, it creates a numerical question with a range-based answer usinganswer_num_range(). Alternatively, ifxis a single numeric value andyis a single numeric value, it also creates a numerical question with a range-based answer usinganswer_num_range(), wherexis the lower bound andyis the upper bound.If
xis a named character vector, it creates a matching question usinganswer_matching(). Any extra choices for the matching question can be provided iny.If
xandyare character vectors, it creates a multiple choice question usinganswer_mcq().If the input format does not match any of the above cases, the function throws an error indicating that the answer format is unsupported.
See also
Other answer-functions:
answer_essay(),
answer_matching(),
answer_mcq(),
answer_multiple(),
answer_none(),
answer_num(),
answer_text(),
answer_true_false(),
answer_upload_file()