grade_result: Grade result of exercise code

Description Usage Arguments Value See Also Examples

View source: R/grade_result.R

Description

Compares the final result of the student code to known pass_if() and fail_if() condition()s. If the student result exactly matches a known case, returns the matching message value.

Usage

1
2
3
4
grade_result(..., correct = NULL, incorrect = NULL,
  grader_args = list(), learnr_args = list(),
  glue_correct = getOption("gradethis_glue_correct"),
  glue_incorrect = getOption("gradethis_glue_incorrect"))

Arguments

...

pass_if() or fail_if() condition()s to check

correct

A character string to display if the student answer matches a known correct answer.

incorrect

A character string to display if the student answer matches a known incorrect answer.

grader_args

A list of parameters passed to grader functions (provided by grade_learnr()). This contains:

  • user_quo: Quoted R code submitted by the user. For example rlang::quo(1)

  • solution_quo: (Optional) Quoted solution R code provided by the *-solution chunk for an exercise.

learnr_args

A list of all parameters passed to grade_learnr() by learnr. See https://rstudio.github.io/learnr/exercises.html#exercise_checking for more details.

glue_correct

A glue string that returns the final correct message displayed. Defaults to getOption("gradethis_glue_correct").

glue_incorrect

A glue string that returns the final incorrect message displayed. Defaults to getOption("gradethis_glue_incorrect").

Value

a graded() object from either pass_if() or fail_if() containing a formatted correct or incorrect message and whether or not a match was found.

See Also

grade_code(), grade_result(), and grade_conditions()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: gradethis_demo()

grade_result(
  pass_if(~ identical(.result, 5), "This is a correct message"),
          grader_args = list(),
          learnr_args = list(last_value = 5, envir_prep = new.env())
)

grade_result(
  pass_if(function(x) identical(x, 5), "This is a correct message"),
  learnr_args = list(last_value = 5)
)

grade_result(
  pass_if(5, "This is a correct message"),
          learnr_args = list(last_value = 5)
)

grade_result(
  fail_if(5, "You were supposed to do this other thing!"),
          pass_if(~ TRUE, "should never reach here"),
          learnr_args = list(last_value = 5)
)

cgamboasanabria/gradethis documentation built on June 11, 2020, 12:15 a.m.