grade_conditions: Grade all specified conditions

Description Usage Arguments Details Value See Also Examples

View source: R/grade_conditions.R

Description

Executes tests against the final result of the user code. If a test throws an error, the test fails and the submitted answer will be marked incorrect.

Usage

1
2
3
4
grade_conditions(..., correct = NULL, incorrect = NULL,
  grader_args = list(), learnr_args = list(),
  glue_correct = getOption("gradethis_glue_correct_test"),
  glue_incorrect = getOption("gradethis_glue_incorrect_test"))

Arguments

...

ignored

correct

A character string to display if all tests pass. This character string will be run through glue::glue_data with:

  • num_correct: Number of correct tests. (Equals num_total)

  • num_total: Number of tests

  • errors: Vector of errors found. (NULL)

incorrect

A character string to display if at least one test fails. This character string will be run through glue::glue_data() with:

  • num_correct: Number of correct tests

  • num_total: Number of tests

  • errors: Vector of errors found

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").

Details

Executes tests against the final result of the user code. If a test throws an error, the test fails and the submitted answer will be marked incorrect.

Value

a grader_graded structure from graded() containing a formatted correct or incorrect message.

See Also

test

Examples

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

example_function <- function(x){
  return(x + 1)
}
grade_conditions(
  pass_if(~ .result(3) == 4),
  pass_if(~ .result(10) == 11),
  grader_args = list(),
  learnr_args = list(last_value = example_function, envir_prep = new.env())
)

grade_conditions(
  pass_if(~ .result(3) == 4),
  fail_if(~ .result(10) == 11),
  grader_args = list(),
  learnr_args = list(last_value = example_function, envir_prep = new.env())
)

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