Question: Question constructor

Description Usage Arguments Examples

Description

This S3 class encapsulates a question for interactive lesson scenarios.

Usage

1
Question(q_text, q_tester, q_type = "console-input", hints = NULL)

Arguments

q_text

the text that will be displayed in the console prompting the user to action.

q_tester

an instance of class QuestionTester.

q_type

the type can be one of console-input, environment-eval. For console-input, execution will be halted until the user has entered some text and hit enter. For environment-eval, the user is required to explicitly call verify() on the question instance.

hints

a list of hints that will be displayed in consecutive order for each incorrect answer.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Instantiate a QuestionTester that tests for a character vector with a single
## "word" of length 5
## The feedback_generator generates some appropriate messages depending on the answer
t1 <- QuestionTester(
    function(x){is.character(x) && length(x)==1 && nchar(x)==5},
    function(x){
        if(! is.character(x)) "that is no word"
        else if(nchar(x) < 5) paste0(x, " has ", nchar(x), " characters and that is not 5")
    }
)
q1 <- Question("Please give a word of length 5", t1)

MichielNoback/bintestr documentation built on May 9, 2019, 3:27 a.m.