pass_if()
and fail_if()
both create passing or failing grades if a given
condition is TRUE
. See graded()
for more information on gradethis
grade-signaling functions.
These functions are also used in legacy gradethis code, in particular
in the superseded function grade_result()
. While previous versions of
gradethis allowed the condition to be determined by a function or
formula, when used in grade_this()
the condition must be a logical TRUE
or FALSE
.
pass_if( cond, message = NULL, ..., env = parent.frame(), praise = getOption("gradethis.pass.praise", FALSE), x = deprecated() ) fail_if( cond, message = NULL, ..., env = parent.frame(), hint = getOption("gradethis.fail.hint", FALSE), encourage = getOption("gradethis.fail.encourage", FALSE), x = deprecated() )
cond | A logical value or an expression that will evaluate to a |
---|---|
message | A character string of the message to be displayed. In all
grading helper functions other than |
... | Ignored |
env | environment to evaluate the glue |
praise | Include a random praising phrase with |
x | Deprecated. Replaced with |
hint | Include a code feedback hint with the failing message? This
argument only applies to |
encourage | Incude a random encouraging phrase with
|
pass_if()
and fail_if()
signal a correct or incorrect grade if
the provided condition is TRUE
.
pass_if
: Pass if cond
is TRUE
.
fail_if
: Fail if cond
is TRUE
.
Other grading helper functions: graded()
, pass()
, fail()
,
pass_if()
, fail_if()
, pass_if_equal()
, fail_if_equal()
.
# Suppose the prompt is to find landmasses in `islands` with land area of # less than 20,000 square miles. (`islands` reports land mass in units of # 10,000 sq. miles.) grader <- # ```{r example-check} grade_this({ fail_if(any(is.na(.result)), "You shouldn't have missing values.") diff_len <- length(.result) - length(.solution) fail_if(diff_len < 0, "You missed {abs(diff_len)} island(s).") fail_if(diff_len > 0, "You included {diff_len} too many islands.") pass_if(all(.result < 20), "Great work!") # Fall back grade fail() }) # ``` .solution <- # ```{r example-solution} islands[islands < 20] # ``` # Peek at the right answer .solution#> Axel Heiberg Hainan Kyushu Melville #> 16 13 14 16 #> New Britain Prince of Wales Southampton Spitsbergen #> 15 13 16 15 #> Taiwan Tierra del Fuego Timor Vancouver #> 14 19 13 12#> <gradethis_graded: [Incorrect] You shouldn't have missing values.>#> <gradethis_graded: [Incorrect] You included 4 too many islands.>#> <gradethis_graded: [Incorrect] You missed 4 island(s).>#> <gradethis_graded: [Correct] Great work!>