R/graded.R
fail_if_code_feedback.Rd
fail_if_code_feedback()
uses code_feedback()
to detect if there are
differences between the user's submitted code and the solution code (if
available). If the exercise does not have an associated solution, or if there
are no detected differences between the user's and the solution code, no
grade is returned.
See graded()
for more information on gradethis grade-signaling
functions.
fail_if_code_feedback( message = NULL, user_code = .user_code, solution_code = .solution_code, ..., env = parent.frame(), hint = TRUE, encourage = getOption("gradethis.fail.encourage", FALSE), allow_partial_matching = getOption("gradethis.allow_partial_matching", TRUE) )
message | A character string of the message to be displayed. In all
grading helper functions other than |
---|---|
user_code | String containing user or solution code. For
ease of use in |
solution_code | String containing user or solution code. For
ease of use in |
... | Arguments passed on to
|
env | Environment used to standardise formals of the user and solution
code. Defaults to retrieving |
hint | Include a code feedback hint with the failing message? This
argument only applies to |
encourage | Incude a random encouraging phrase with
|
allow_partial_matching | A logical. If |
Signals an incorrect grade with feedback if there are differences between the submitted user code and the solution code. If solution code is not available, no grade is returned.
Other grading helper functions: graded()
, pass()
, fail()
,
pass_if()
, fail_if()
, pass_if_equal()
, fail_if_equal()
.
# Suppose the exercise prompt is to generate 5 random numbers, sampled from # a uniform distribution between 0 and 1. In this exercise, you know that # you shouldn't have values outside of the range of 0 or 1, but you'll # otherwise need to check the submitted code to know that the student has # chosen the correct sampling function. grader <- # ```{r example-check} grade_this({ fail_if(length(.result) != 5, "I expected 5 numbers.") fail_if( any(.result < 0 | .result > 1), "I expected all numbers to be between 0 and 1." ) # Specific checks passed, but now we want to check the code. fail_if_code_feedback() # All good! pass() }) # ``` .solution_code <- " # ```{r example-check} runif(5) # ``` " # Not 5 numbers... grader(mock_this_exercise(runif(1), !!.solution_code))#> <gradethis_graded: [Incorrect] I expected 5 numbers.>#> <gradethis_graded: [Incorrect] #> I expected all numbers to be between 0 and 1. #> ># Passes specific checks, but hard to tell so check the code... grader(mock_this_exercise(runif(5, 0.25, 0.75), !!.solution_code))#> <gradethis_graded: [Incorrect] #> In `runif(5, 0.25, 0.75)`, I expected `0` where you wrote `0.25`. #> >#> <gradethis_graded: [Incorrect] #> I expected you to call `runif()` where you called `rbinom()`. #> >#> <gradethis_graded: [Correct] Beautiful! Correct!>