Skip to contents

Add a multiple-choice or single-choice question to a dataframe, drawing answers from a pool of possibilities and validation and/or transforming inputs.

Usage

add_from_pool(
  question,
  image = NA,
  explanation = NA,
  answer_pool = NA,
  correct_ids = NA,
  keywords = NA,
  df = NA
)

Arguments

question

Question text.

image

Image filename (optional).

explanation

Explanation for the correct answer (optional).

answer_pool

Tibble of answer choices, with id and text columns.

correct_ids

Numeric vector of correct answer ids, as in answer_pool.

df

Dataframe to add question to.

Value

The provided dataframe df, with an additional row. If a dataframe is not provided, a new one is created.

Credits

Brighton Pauli, 2022.

See also

Examples

df <- examling::build_question_df()
df <- add_from_pool(
 question = "What color is a male cardinal?",
 answer_pool = data.frame(text=c("Red", "Green", "Blue"), id = seq_len(3)),
 correct_ids = c(1),
 df = df
)
df
#>                         question image correct   incorrect explanation
#> 1 What color is a male cardinal?    NA     Red Green, Blue          NA