Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add second level of quick restore that can pull from tutorial storage if available #794

Merged
merged 6 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- When the `LC_ALL` environment variable is `"C"` or `"C.UTF-8"`, R may ignore the `LANGUAGE` environment variable, which means that learnr may not be able to control the language of R's messages. learnr's tests no longer test R message translations in these cases. If you are deploying a tutorial written in a language other than English, you should ensure that the `LC_ALL` environment variable is not set to `"C"` or `"C.UTF-8"` and you may need to set the `LANGUAGE` variable via an `.Renviron` file rather than relying on learnr (#801).

- Added a new quick restore option that restores both the last submitted exercise code and the output of that submission, if the output is available to be restored. This option is enabled by setting the global option `tutorial.quick_restore = 2` or the environment variable `TUTORIAL_QUICK_RESTORE=2`. This option augments the quick restore value when `TRUE` or `1`, wherein only the last submitted **code** is restored, such that users will need to click the "Submit" button to evaluate and see the output. (#794)

# learnr 0.11.4

- Moved curl from Imports to Suggests. curl is only required when using an external evaluator (#776).
Expand Down
25 changes: 18 additions & 7 deletions R/exercise.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ cache_complete_exercise <- function(exercise) {
exercise
}

get_opt_quick_restore <- function() {
env <- Sys.getenv("TUTORIAL_QUICK_RESTORE", NA)
if (!is.na(env)) return(env)

opt <- getOption("tutorial.quick_restore", NA)
if (isTRUE(opt)) return("1")
if (isFALSE(opt)) return("0")
if (!is.na(opt)) as.character(opt) else "0"
}

# run an exercise and return HTML UI
setup_exercise_handler <- function(exercise_rx, session) {

Expand Down Expand Up @@ -36,13 +46,8 @@ setup_exercise_handler <- function(exercise_rx, session) {
# short circuit for restore (we restore some outputs like errors so that
# they are not re-executed when bringing the tutorial back up)
if (exercise$restore) {
if (
getOption(
"tutorial.quick_restore",
identical(Sys.getenv("TUTORIAL_QUICK_RESTORE", "0"), "1")
)
) {
# don't evaluate at all if quick_restore is enabled
if (identical(get_opt_quick_restore(), "1")) {
# quick_restore: don't evaluate at all if super fast restore is enabled
rv$result <- list()
return()
}
Expand Down Expand Up @@ -70,6 +75,12 @@ setup_exercise_handler <- function(exercise_rx, session) {
rv$result <- output
return()
}

if (identical(get_opt_quick_restore(), "2")) {
# quick_restore: previous evaluated output wasn't stored, don't eval now
rv$result <- list()
return()
}
}

# get exercise evaluator factory function (allow replacement via global option)
Expand Down
Loading