Multiple Choice Example

This is an exercise containing two multiple choice questions about the elements of the periodic table.

The whole example as an .Rmd-file can be downloaded here:

The content of the file can be viewed by expanding the following field.

Note that the displayed code below is not highlighted as it would be in the downloaded file, so downloading it is recommended for better readability!

```{r answers/solutions, echo = FALSE, results = "hide"}
library(exams)
# Initialize lists for the questions, answers, solutions, types, explanations (tolerances are not needed if there are no numeric questions)

answers <- list()
solutions <- list()
types <- list()
explanations <- list()

# Define Question 1: Which of the following elements are metals?
answers[[1]] <- c("Iron (Fe)", "Oxygen (O)", "Aluminium (Al)", "Nitrogen (N)")
solutions[[1]] <- explanations[[1]] <- c(TRUE, FALSE, TRUE, FALSE)  # Correct answers: Fe and Al
types[[1]] <- "mchoice"


# Define Question 2: Which of the following elements are metalloids?
answers[[2]] <- c("Silicon (Si)", "Boron (B)", "Helium (He)", "Arsenic (As)")
solutions[[2]] <- explanations[[2]] <- c(TRUE, TRUE, FALSE, TRUE)  # Correct answers: Si, B, and As
types[[2]] <- "mchoice"
```

Question
========

*Question 1*

Which of the following elements are metals?

##ANSWER1##

*Question 2*

Which of the following elements are metalloids?

##ANSWER2##

```{r questionlist, echo = FALSE, results = "asis"}
answerlist(unlist(answers), markup = "markdown")

```

Solution
========

*Solution 1*

Iron (Fe) and Aluminium (Al) are metals, while Oxygen (O) and Nitrogen (N) are gases.

*Solution 2*

Silicon (Si), Boron (B), and Arsenic (As) are metalloids. Helium (He) is a noble gas.

```{r solutionlist, echo = FALSE, results = "asis"}
# Convert solutions to "True" or "False"
explanations <- lapply(solutions, function(x) ifelse(x, "True", "False"))
solutions <- lapply(solutions, mchoice2string)

# Display explanations
answerlist(unlist(explanations), markup = "markdown")

```

Meta-information
================
exname: example_mchoice
extitle: metalls and metalloids
extype: cloze
exsolution: `r paste(solutions, collapse = "|")`
exclozetype: `r paste(types, collapse = "|")`
exshuffle: TRUE
exversion: v1

After conversion with R/exams the exercise looks like this for different output types.

Creating the List Structure

This section creates and fills the lists which contain the questions, answers, etc.. The answers list contains the answer options for the questions. The solution to the question, the type of question, as well as a more elaborate explanation are specified for each question.

Warning

The following code has to be placed within a code chunk in the .Rmd-file. See the first problem in this section of the FAQ

library(exams)

# Initialize lists for the questions, answers, solutions, types, explanations (tolerances are not needed if there are no numeric questions)
answers <- list()
solutions <- list()
types <- list()
explanations <- list()

# Define Question 1: Which of the following elements are metals?
answers[[1]] <- c("Iron (Fe)", "Oxygen (O)", "Aluminium (Al)", "Nitrogen (N)")
solutions[[1]] <- explanations[[1]] <- c(TRUE, FALSE, TRUE, FALSE)  # Correct answers: Fe and Al
types[[1]] <- "mchoice"


# Define Question 2: Which of the following elements are metalloids?
answers[[2]] <- c("Silicon (Si)", "Boron (B)", "Helium (He)", "Arsenic (As)")
solutions[[2]] <- explanations[[2]] <- c(TRUE, TRUE, FALSE, TRUE)  # Correct answers: Si, B, and As
types[[2]] <- "mchoice"

Question Section

The next section contains the question text, including the marked spaces ##ANSWERi## for the answer fields and a necessary code section, which does some formating which is required for the later conversion. This is markdown text, which will appear bold/italic/etc. after conversion.

It also includes a code chunk, which converts the answers list to the necessary format.

Question
========

*Question 1*

Which of the following elements are metals?

##ANSWER1##

*Question 2*

Which of the following elements are metalloids?

##ANSWER2##

```{r questionlist, echo = FALSE, results = "asis"}
answerlist(unlist(answers), markup = "markdown")

```

Solution Section

In this section, additional information and/or the exact solutions can be given. In this case, there is a more elaborate explanation as a solution for each question. Additionally, the code chunk included below converts the TRUE and FALSE objects into a more readable format of “True” and “False”, however this could be in any other format as well.

Solution
========

*Solution 1*

Iron (Fe) and Aluminium (Al) are metals, while Oxygen (O) and Nitrogen (N) are gases.

*Solution 2*

Silicon (Si), Boron (B), and Arsenic (As) are metalloids. Helium (He) is a noble gas.

```{r solutionlist, echo = FALSE, results = "asis"}
# Convert solutions to "True" or "False"
explanations <- lapply(solutions, function(x) ifelse(x, "True", "False"))
solutions <- lapply(solutions, mchoice2string)

# Display explanations
answerlist(unlist(explanations), markup = "markdown")

```

Meta-information Section

The next section contains the meta information needed for conversion. See here for an explanation of the meta-information.

The “source code” is written in markdown and contains inline R code.

Meta-information
================
exname: example_schoice
extitle: molmass and lightest element
extype: cloze
exsolution: `r paste(solutions, collapse = "|")`
exclozetype: `r paste(types, collapse = "|")`
exshuffle: TRUE
exversion: v1

If the “code” above is evaluated, the section looks like this:

Meta-information
================
exname: example_mchoice
extitle: metalls and metalloids
extype: cloze
exsolution: c(TRUE, FALSE, TRUE, FALSE)|c(TRUE, TRUE, FALSE, TRUE)
exclozetype: mchoice|mchoice
exshuffle: TRUE
exversion: v1