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

Multi-language chunks and chained setup chunks #390

Merged
merged 20 commits into from
Jul 14, 2020

Conversation

nischalshrestha
Copy link
Contributor

@nischalshrestha nischalshrestha commented Jun 17, 2020

Description

This PR introduces a behavior change as well as minor improvements for exercise and setup chunks and the way they are handled in the backend.

Behavior Additions

  1. Setup chunks can now be chained using the exercise.setup = 'label'
  2. Similarly, exercises can also be chained using exercise.setup = 'label'
  3. When processing each exercise, exercise.R now generates anexercise.Rmd using a duplicate of all the relevant setup chunks.

Given these changes, there are some things to consider when constructing lessons with chained setup chunks. For example, only the exercise.setup option can be used in order to form a chain between setup chunks and exercises. The -setup labelling scheme is not considered for chaining purposes (1). When chaining exercises, pre-filled code is used to serve as the setup code for another exercise (2), not user input code.

These additions also have several benefits for both reducing repetition for the instructor and a step towards polyglot lessons. First, we retain the same mechanism for providing a setup chunk for an exercise using the exercise.setup. Being able to build on setup code can alleviate previously mentioned issues (see #72 and #170) reducing the need to copy-paste previous setup code, which can be tedious. Second, since exercise.R now produces a proper exercise.Rmd which is constructed from raw knitr chunk information (3), it is a BIG step towards multi-language support because we have access to all knitr options, such as engine (see #213 and #310).

Minor improvements

  • an include=FALSE option is set on setup chunks by default to prevent printing output (if any)
  • setting a non-existent label with exercise.setup = 'label' will now throw an error

Minimal reproducible example

There is a demo available in the tutorials folder which demonstrates chaining of setup chunks, as well as chaining of exercise chunks with pre-filled code.

Tasks:

  • set knitr option for each exercise using rmd approach
  • documentation
  • address the rest of the suggestions

R/exercise.R Outdated Show resolved Hide resolved
R/exercise.R Outdated Show resolved Hide resolved
R/exercise.R Outdated Show resolved Hide resolved
R/exercise.R Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
R/knitr-hooks.R Outdated Show resolved Hide resolved
R/exercise.R Outdated Show resolved Hide resolved
R/exercise.R Outdated Show resolved Hide resolved
R/setup-cache.R Outdated Show resolved Hide resolved
R/knitr-hooks.R Outdated Show resolved Hide resolved
R/knitr-hooks.R Outdated Show resolved Hide resolved
R/exercise.R Outdated Show resolved Hide resolved
R/knitr-hooks.R Outdated Show resolved Hide resolved
R/knitr-hooks.R Outdated Show resolved Hide resolved
R/exercise.R Show resolved Hide resolved
R/exercise.R Show resolved Hide resolved
R/exercise.R Outdated Show resolved Hide resolved
R/exercise.R Outdated Show resolved Hide resolved
- set proper environment for exercise rmd rendering
- cleanup of code
R/exercise.R Outdated Show resolved Hide resolved
@cpsievert cpsievert self-requested a review July 13, 2020 18:25
Copy link
Contributor

@cpsievert cpsievert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending fix to last comment

@nischalshrestha nischalshrestha changed the title Feature: Chained setup chunks. Multi-language chunks and chained setup chunks Jul 14, 2020
@nischalshrestha nischalshrestha merged commit 5a061d0 into master Jul 14, 2020
@nischalshrestha nischalshrestha deleted the feature/chained-setup-chunks branch July 14, 2020 13:09
sjgknight pushed a commit to sjgknight/learnr that referenced this pull request Aug 10, 2021
* initial working version of chained setup chunks

* fixed a setup chain bug and added error handling for exercise.setup label

* better error handling of cycles, and added tests for cycles

* addressed some suggestions and handled default exercise.setup case

* move knitr setting to rmd, dont process empty chunks

* addressing suggestions and fixing issue with losing chunk structure

* Update NEWS.md

Co-authored-by: Barret Schloerke <barret@rstudio.com>

* cleaning up code

* Updates:

- fixed a bug where exercise checker was not grabbed as character
- now storing exercise along with its setup chunks to cache
- added some documentation of chaining setup chunks and exercises

* More updates:

- Restructured exercise cache
- Minimized preserved options forwarding to browser to just engine
- Better handling of exercise and setup chunks processing in knitr hooks
- Better handling of constructing the Rmd for evaluating exercises
- Fixed issue with dput_to_string so that it properly retains code structure
- Slight enhancement to chained setup chunk docs

* Updates:

- We longer forward checking code to browser, and instead cache it
- The exercise cache now includes the checking code

* Update R/initialize.R

Co-authored-by: Barret Schloerke <barret@rstudio.com>

* Updates:

- We only forward hint and solution chunks to browser
- We rely on a boolean variable for checking if we need to run versus check
- Remove check and code check logic on browser side and use flag for submit button

* Updates:

- set proper environment for exercise rmd rendering
- cleanup of code

* remove checker_fn_exists variable and use explicit check instead

* change envir_result to envir in exercise.R

* variable assignment cleanup for output_file

Co-authored-by: Barret Schloerke <barret@rstudio.com>

* Merge master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants