-
Notifications
You must be signed in to change notification settings - Fork 241
Store exercises and questions in list in cache env #571
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
Merged
gadenbuie
merged 24 commits into
rstudio:master
from
gadenbuie:570-order-tutorial-state
Aug 24, 2021
Merged
Store exercises and questions in list in cache env #571
gadenbuie
merged 24 commits into
rstudio:master
from
gadenbuie:570-order-tutorial-state
Aug 24, 2021
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Bring questions and exercises into an `objects` list in a single env `tutorial_cache_env` - Give `exercise` objects a `learnr_exercise` class - Refactor getters and setters to use `get_tutorial_cache()` and `set_tutorial_cache()` - Handle "__setup__" chunk directly in knitr hooks
When `label = NULL` in `get_tutorial_state()`, the state is returned as a list in order of appearance of the interactive elements
With custom format method to align appearance with typical exercise objects
gadenbuie
commented
Aug 16, 2021
fc736b2 to
062efe7
Compare
schloerke
reviewed
Aug 16, 2021
schloerke
reviewed
Aug 17, 2021
…tutorial_cache()`
Previously we tried to store the global setup in a separate shiny prerendered chunk with the name "__setup__". This change avoids potential exercise id clashes with a user-created chunk labelled "__setup_-". It also avoids a tricky knitr source hook issue when calling `rmarkdown::run()` interactively that would cause the global setup chunk to be lost.
I'd prefer `learnr_exercise` but questions are super-classed `tutorial_question` (and have been for a while)
- Treat as exercise support - Force evaluation of `global_setup` if used in exercises - Add related tests
schloerke
approved these changes
Aug 23, 2021
gadenbuie
commented
Aug 23, 2021
it shouldn't be evaluated locally, but it should be used by external evaluators with `evaluate_global_setup = TRUE`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #570 and refactors the exercise and question cache env into a single object in a
tutorial_cache_env.Tutorial Item Cache
We now store exercises and questions in list in cache env rather than two separate envs:
objectslist in a single envtutorial_cache_envexerciseobjects now have atutorial_exerciseclassget_tutorial_cache()andset_tutorial_cache()The objects in the tutorial cache are now also exposed in the
$itemselement ofget_tutorial_info(). This lets authors access the list of items in a tutorial with their associatedorder,type,labeland underlyingdata.Tutorial State
By storing the exercise and question objects in a named list populated by order of appearance in the tutorial, we can now return the tutorial state in order. When
label = NULLinget_tutorial_state(), the state is returned as a list in order of appearance of the interactive elements. This call will still take a reactive dependency on all questions/exercises, but users can access specific questions/exercises by providing thelabelargument.Exercise Objects
Finally, I added gave the exercise objects a class --
tutorial_exerciseto parallel the existingtutorial_questionclass. This class gains a print method that's a small wrapper around the exercise chunk formatting functions that are used for writing the exercise temp Rmd. I updatedmock_exercise()to use this formatter as well:Internal Changes
Internally, I removed the finicky knitr source hook that was used to store the global setup chunk as a special object in the tutorial cache. Now, rather than handling it with a special knitr hook — which was brittle, esp. when the tutorial is rendered interactively — I've simply in-lined the global setup code into the exercise object. This makes the exercise object more consistent and less reliant on process steps that only happen in the Shiny observer handling exercise submissions.
A knock-on effect from this change is that we now have better handlers for the special
setup-global-exercisechunk, which is a separate setup chunk that can provide setup code for all exercises. This chunk replaces the global setup chunk, although for learnr tutorials that are run locally thesetup-global-exercisechunk is effectively an additional setup chunk for each exercise. As a result, we force evaluation of theexercise$global_setupcode when we know that it came from thesetup-global-exercisechunk. (Since this relies on attributes, we assume that any evaluator that serializes the exercise will know to setevaluate_global_setup = TRUEwhen callingevaluate_exercise().)Finally, I also added an internal helper —
prepare_tutorial_cache_from_source()— that will let us better test the results of thermarkdown::render()step. These kinds of tests are very much needed but missing in our current test suite. A happy side-effect is that this function can be used to read the exercise/question objects from a tutorial without having to run the tutorial.