pass_if_equal()
and fail_if_equal()
are two graded()
helper functions
that signal a passing or a failing grade if two values are equal. They are
designed to easily compare the returned value of the student's submitted
code with the value returned by the solution or another known value:
Both functions find and use .result
as the default for x
, the first
item in the comparison. .result
is the last value returned from the
user's submitted code.
pass_if_equal()
additionally finds and uses .solution
as the default
expected value y
.
See graded()
for more information on gradethis grade-signaling
functions.
pass_if_equal( y = .solution, message = getOption("gradethis.pass", "Correct!"), x = .result, ..., env = parent.frame(), praise = getOption("gradethis.pass.praise", FALSE) ) fail_if_equal( y, message = getOption("gradethis.fail", "Incorrect"), x = .result, ..., env = parent.frame(), hint = getOption("gradethis.fail.hint", FALSE), encourage = getOption("gradethis.fail.encourage", FALSE) )
y | The expected value against which |
---|---|
message | A character string of the message to be displayed. In all
grading helper functions other than |
x | First item in the comparison. By default, when used inside
|
... | Additional arguments passed to |
env | environment to evaluate the glue |
praise | Include a random praising phrase with |
hint | Include a code feedback hint with the failing message? This
argument only applies to |
encourage | Incude a random encouraging phrase with
|
Returns a passing or failing grade if x
and y
are equal.
pass_if_equal
: Signal a passing grade only if x
and y
are
equal.
fail_if_equal
: Signal a failing grade only if x
and y
are
equal.
Other grading helper functions: graded()
, pass()
, fail()
,
pass_if()
, fail_if()
, pass_if_equal()
, fail_if_equal()
.
# Suppose our prompt is to find the cars in `mtcars` with 6 cylinders... grader <- # ```{r example-check} grade_this({ # Automatically pass if .result equal to .solution pass_if_equal() fail_if_equal(mtcars[mtcars$cyl == 4, ], message = "Not four cylinders") fail_if_equal(mtcars[mtcars$cyl == 8, ], message = "Not eight cylinders") # Default to failing grade with feedback fail() }) # ``` .solution <- # ```{r example-solution} mtcars[mtcars$cyl == 6, ] # ``` # Correct! grader(mock_this_exercise(mtcars[mtcars$cyl == 6, ], !!.solution))#> <gradethis_graded: [Correct] Success! Correct!># These fail with specific messages grader(mock_this_exercise(mtcars[mtcars$cyl == 4, ], !!.solution))#> <gradethis_graded: [Incorrect] Not four cylinders>#> <gradethis_graded: [Incorrect] Not eight cylinders># This fails with default feedback message grader(mock_this_exercise(mtcars[mtcars$mpg == 8, ], !!.solution))#> <gradethis_graded: [Incorrect] #> Incorrect. I expected you to call `structure()` where you called `[`. #> Please try again. #> >