check_blanks: Checking fill-in-the-blanks problems

Description Usage Arguments Details Examples

Description

Specify a binding pattern in terms of an expression where elements like ..one.. or ..x.., etc set the names to be bound to the corresponding part of the code.

Usage

1
check_blanks(ex, pat, ...)

Arguments

ex

the expression to check, e.g. USER_CODE

pat

a quoted expression containing the anticipated correct form. Use elements such as ..one.. to define a blank. If there are multiple expressions (say, to be matched against multiple lines of a submission) pat should be a list of quoted expressions.

...

tests to apply to expressions in ex. These are typically made with passif(), failif(), and so on.

Details

For formulas, the ~ should be encompassed by the named element. For instance, if the user is shown a statement like mean( ~ hp, data = mtcars), the blanks statement should be something like mean(..v.., data = mtcars) and NOT mean( ~ ..v.., data = mtcars).

In pat, you can use . (for a name or call) and ... (for remaining arguments) to stand for components of the pattern you don't care about.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
submission <- for_checkr(quote({a <- 3; b <- 4; res <- sqrt(a^2 + b^2)}))
submission2 <- for_checkr(quote({a <- 3; b <- 4; res <- sin(a^2 + b^2)}))
# a template with a blank ..fn..
as_posted <- quote(res <- ..fn..(a^2 + b^2))
check_blanks(submission, as_posted,
   insist(fn == quote(sqrt), "{{fn}} is not the right function."),
   passif(TRUE, "Right! You're using the square-root function."))
check_blanks(submission2, as_posted,
   insist(fn == quote(sqrt), "{{fn}} is not the right function."),
   passif(TRUE, "Right! You're using the square-root function."))
as_posted2 <- quote(b <- ..bval..)
check_blanks(submission, list(as_posted, as_posted2),
   insist(fn == quote(sqrt), "Wrong function."),
   insist(bval == 5, "`b` is not supposed to be {{bval}}."))

# Multiple blanks
as_posted <- for_checkr(quote({res <- ..fn..(`+`(`^`(a, ..exp1..), `^`(b, ..exp2..)))}))

dtkaplan/checkr documentation built on May 15, 2019, 4:59 p.m.