Skip to content

Commit

Permalink
Remove exercise.error.checker in favor of exercise.error.check.code a…
Browse files Browse the repository at this point in the history
…nd -error-check chunks, closes #356
  • Loading branch information
cpsievert committed Aug 27, 2020
1 parent 6de2a01 commit 17acff9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
28 changes: 15 additions & 13 deletions R/exercise.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,20 +391,22 @@ render_exercise <- function(exercise, envir, envir_prep) {
if (grepl(pattern, msg, fixed = TRUE)) {
return(exercise_result_timeout())
}
# Run the condition through an error checker (the exercise could be to throw an error!)
checker_feedback <- try_checker(
exercise, "exercise.error.checker",
check_code = exercise$check,
envir_result = envir,
evaluate_result = evaluate_result,
envir_prep = envir_prep,
last_value = e
)
if (is_exercise_result(checker_feedback)) {
checker_feedback
} else {
exercise_result_error(msg)
error_check_code <- exercise$error_check %||% exercise$options$exercise.error.check.code
if (length(error_check_code)) {
# Run the condition through an error checker (the exercise could be to throw an error!)
checker_feedback <- try_checker(
exercise, "exercise.checker",
check_code = error_check_code,
envir_result = envir,
evaluate_result = evaluate_result,
envir_prep = envir_prep,
last_value = e
)
if (is_exercise_result(checker_feedback)) {
return(checker_feedback)
}
}
exercise_result_error(msg)
})

if (is_exercise_result(output_file)) {
Expand Down
2 changes: 2 additions & 0 deletions R/knitr-hooks.R
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ install_knitr_hooks <- function() {
all_chunks <- get_all_chunks(options)

code_check_chunk <- get_knitr_chunk(paste0(options$label, "-code-check"))
error_check_chunk <- get_knitr_chunk(paste0(options$label, "-error-check"))
check_chunk <- get_knitr_chunk(paste0(options$label, "-check"))
solution <- get_knitr_chunk(paste0(options$label, "-solution"))

Expand All @@ -294,6 +295,7 @@ install_knitr_hooks <- function() {
exercise_cache <- list(setup = all_setup_code,
chunks = all_chunks,
code_check = code_check_chunk,
error_check = error_check_chunk,
check = check_chunk,
solution = solution,
options = options,
Expand Down
8 changes: 4 additions & 4 deletions R/options.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#' number of lines in the code chunk).
#' @param exercise.checker Function used to check exercise answers
#' (e.g., `gradethis::grade_learnr()`).
#' @param exercise.error.checker Function used to check exercise answers
#' (e.g., `gradethis::grade_learnr_error()`).
#' @param exercise.error.check.code A string containing R code to use for checking
#' code when an exercise evaluation error occurs (e.g., `"gradethis::grade_code()"`).
#' @param exercise.completion Use code completion in exercise editors.
#' @param exercise.diagnostics Show diagnostics in exercise editors.
#' @param exercise.startover Show "Start Over" button on exercise.
Expand All @@ -25,7 +25,7 @@ tutorial_options <- function(exercise.cap = "Code",
exercise.timelimit = 30,
exercise.lines = NULL,
exercise.checker = NULL,
exercise.error.checker = NULL,
exercise.error.check.code = NULL,
exercise.completion = TRUE,
exercise.diagnostics = TRUE,
exercise.startover = TRUE)
Expand All @@ -39,7 +39,7 @@ tutorial_options <- function(exercise.cap = "Code",
eval(parse(text = sprintf(set_option_code, "exercise.timelimit")))
eval(parse(text = sprintf(set_option_code, "exercise.lines")))
eval(parse(text = sprintf(set_option_code, "exercise.checker")))
eval(parse(text = sprintf(set_option_code, "exercise.error.checker")))
eval(parse(text = sprintf(set_option_code, "exercise.error.check.code")))
eval(parse(text = sprintf(set_option_code, "exercise.completion")))
eval(parse(text = sprintf(set_option_code, "exercise.diagnostics")))
eval(parse(text = sprintf(set_option_code, "exercise.startover")))
Expand Down
6 changes: 3 additions & 3 deletions man/tutorial_options.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 17acff9

Please sign in to comment.