Learn R Programming

exams (version 2.4-1)

mchoice2string: Convenience Functions for Exam Formatting

Description

A collection of convenience functions for formatting in exam generation that can be used for switching between suitable logical/text/numeric representations of multiple choice solutions.

Usage

mchoice2string(x, single = FALSE)
  string2mchoice(x, single = FALSE)
  mchoice2text(x, markup = c("latex", "markdown"))
  answerlist(..., sep = ". ", markup = c("latex", "markdown"))

Arguments

x

an object, see below for examples.

single

logical. Should the function check whether exactly a single answer is true?

...

character vectors to be included in answer lists.

sep

character for separation between vectors, see below for examples.

markup

character indicating which markup (LaTeX vs. Markdown) should be generated.

Details

Three convenience functions for facilitating work with multiple choice solutions of exams. All have almost trivial definitions, see also examples below.

See Also

exams

Examples

Run this code
## multiple choice answer
mc <- c(TRUE, FALSE, TRUE, FALSE, FALSE)

## switching to string representation
mchoice2string(mc)

## reverse string encoding
string2mchoice("10100")

## switching to text
mchoice2text(mc)

## generating answerlist based on questions,
## solutions and explanations
qu <- c("Zurich is the capital of Switzerland.",
        "Italian is an official language in Switzerland.",
        "Switzerland is part of the European Union.")
sol <- c(FALSE, TRUE, FALSE)
ex <- c("The capital of Switzerland is Bern.",
        "The four official languages are: German, French, Italian, Romansh.",
	"Switzerland is part of the Schengen Area but not the European Union.")
answerlist(qu)
answerlist(ifelse(sol, "True", "False"), ex)

Run the code above in your browser using DataLab