any_of_exprs
: Test that the user's expression matches any of several possible expressions.
calculates_same_value
: Test that the user's expression evaluates to a certain value.
expr_creates_var
: Test that a new variable has been created.
expr_identical_to
: Test that the user has entered a particular expression.
expr_is_a
: Test that the expression itself is of a specific class
.
expr_uses_func
: Test that a particular function has been used.
func_of_newvar_equals
: Test the result of a computation such as mean(newVar)
applied to a specific (user-named) variable created in a previous question.
omnitest
: Test for a correct expression, a correct value, or both.
val_has_length
: Test that the value of the expression has a particular length
.
val_matches
: Test that the user's expression matches a regular expression (regex
).
var_is_a
: Test that the value of the expression is of a specific class
.
customTests.R
(case-sensitive) is automatically created in the lesson
directory. If it's not there already, you can create the file manually.In this file, you can write your own answer tests. These answer tests are then available to you just the same as any of the standard tests. However, the scope of a custom answer test is limited to the lesson within which you've defined it.
Each custom answer test is simply an R function that follows a few basic rules:
creates_matrix_with_n_rows
).e <- get("e", parent.frame())
, which gives you access to the
environmente
. Any important information, such as the expression
typed by the user, will be available to you throughe
.e$expr
and
the value of the expression withe$val
.
Note thate$expr
comes in
the form of an unevaluated Rexpression
.TRUE
if the test is passed andFALSE
otherwise. You should be careful that no other
value could be returned (e.g.NA
,NULL
, etc.)skip
s your question, this is the answer that will be
entered on his or her behalf.If you're using the
You can specify any number of answer tests. If you use more than one, you
must separate them with semicolons. If you do not specify any answer tests
for a command question, then the default test will be used. The default
test is omnitest(correctExpr='
, which will
simply check that the user's expression matches the expression that you
provided as a correct answer.
In many cases, the default answer test will provide sufficient vetting of a user's response to a command question. While it is somewhat restrictive in the sense that it requires an exact match of expressions (ignoring whitespace), it is liberating to the course author for two reasons.
any_of_exprs
,
calculates_same_value
,
expr_creates_var
,
expr_identical_to
, expr_is_a
,
expr_uses_func
,
func_of_newvar_equals
,
omnitest
, val_has_length
,
val_matches
, var_is_a