Please use
grade_this()
mixed with pass(), pass_if_equal(), fail(), and/or fail_if_equal().
grade_result() and grade_result_strict() both take a set of
pass_if()/fail_if() conditions, evaluate them, and return a final
graded() object. For grade_result_strict() to return a correct grade,
every pass_if() condition must be met, and every fail_if() condition must
not be met. On the other hand, grade_result()'s final grade reflects the
first satisfied condition (if no conditions are met, the final grade can be
controlled by default_correct and default_message).
grade_result( ..., correct = NULL, incorrect = NULL, glue_correct = getOption("gradethis.glue_correct"), glue_incorrect = getOption("gradethis.glue_incorrect"), default_correct = "auto", default_message = NULL, grader_args = deprecated(), learnr_args = deprecated() ) grade_result_strict( ..., correct = NULL, incorrect = NULL, glue_correct = getOption("gradethis.glue_correct_test"), glue_incorrect = getOption("gradethis.glue_incorrect_test"), grader_args = deprecated(), learnr_args = deprecated() ) condition(x, message, correct)
| ... | |
|---|---|
| correct | logical whether the condition is the correct answer. |
| incorrect | A character string to display if the student answer matches a known incorrect answer. |
| glue_correct | A glue string that returns the final correct message
displayed. Defaults to |
| glue_incorrect | A glue string that returns the final incorrect message
displayed. Defaults to |
| default_correct | In the event that no |
| default_message | In the event that no |
| grader_args | A list of parameters passed to
|
| learnr_args | A list of all parameters passed to
|
| x | A formula, function, or value, that returns |
| message | character string for message returned (usually passed in from
|
a function whose first parameter should be an environment that contains
all necessary information to compare the user's result. The result of the returned function
will be a graded() object containing a formatted correct or incorrect message.
# The student submits code that returns `5` submitted_5 <- mock_this_exercise(.user_code = 2 + 3) # grade_result() returns a function that is called on the student's # submission. The *-check chunk of the exercise might contain the following # grade_result() code. When you're writing your tutorial, you can ignore the # `(submitted_5)`, we're using that notation here to preview what this # `grade_result()` will do with the mock submission. grade_result( fail_if(~ identical(.result, 4), "Try adding 1"), pass_if(~ identical(.result, 5), "You got 5, great!"), fail_if(~ TRUE, "Some generic failing message.") )(submitted_5)#> <gradethis_graded: [Correct] Wonderful! You got 5, great! >grade_result_strict( pass_if(~ identical(.result, 5), "You got 5, great!"), fail_if(~ !is.integer(.result), "I expected an integer") )(submitted_5)#> <gradethis_graded: [Incorrect] 1/2 correct! Let's try it again.># Suppose our exercise asks the student to write a function that adds 1 to # the value of its only argument. The student submits: submitted_fn <- mock_this_exercise( .user_code = function(x) { x + 2 } ) # We can check submissions for this exercise using `grade_result()`. Note that # because all checks in this `grade_result()` are `fail_if()` statements, if # the student's submission passes all of the checks, then `grade_result()` # will return a correct grade. grade_result( fail_if(~ !is.function(.result), "I expected a function."), fail_if(~ .result(1) != 2, "Your function should add one.") )(submitted_fn)#> <gradethis_graded: [Incorrect] #> Your function should add one. Try it again. Perseverence is the key #> to success. #> ># To learn more about using grade_result() and grade_code() with learnr, see: if (FALSE) gradethis_demo()