|
| 1 | +```{webr} |
| 2 | +#| edit: false |
| 3 | +#| output: false |
| 4 | +webr::install("gradethis", quiet = TRUE) |
| 5 | +library(gradethis) |
| 6 | +options(webr.exercise.checker = function( |
| 7 | + label, user_code, solution_code, check_code, envir_result, evaluate_result, |
| 8 | + envir_prep, last_value, engine, stage, ... |
| 9 | +) { |
| 10 | + if (is.null(check_code)) { |
| 11 | + # No grading code, so just skip grading |
| 12 | + invisible(NULL) |
| 13 | + } else if (is.null(label)) { |
| 14 | + list( |
| 15 | + correct = FALSE, |
| 16 | + type = "warning", |
| 17 | + message = "All exercises must have a label." |
| 18 | + ) |
| 19 | + } else if (is.null(solution_code)) { |
| 20 | + list( |
| 21 | + correct = FALSE, |
| 22 | + type = "warning", |
| 23 | + message = htmltools::tags$div( |
| 24 | + htmltools::tags$p("A problem occurred grading this exercise."), |
| 25 | + htmltools::tags$p( |
| 26 | + "No solution code was found. Note that grading exercises using the ", |
| 27 | + htmltools::tags$code("gradethis"), |
| 28 | + "package requires a model solution to be included in the document." |
| 29 | + ) |
| 30 | + ) |
| 31 | + ) |
| 32 | + } else { |
| 33 | + gradethis::gradethis_exercise_checker( |
| 34 | + label = label, solution_code = solution_code, user_code = user_code, |
| 35 | + check_code = check_code, envir_result = envir_result, |
| 36 | + evaluate_result = evaluate_result, envir_prep = envir_prep, |
| 37 | + last_value = last_value, stage = stage, engine = engine) |
| 38 | + } |
| 39 | +}) |
| 40 | +``` |
0 commit comments