Skip to content

Commit

Permalink
Multi-language chunks and chained setup chunks (rstudio#390)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nischalshrestha authored Jul 14, 2020
1 parent 1c9d9e3 commit 128d531
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions setup-chunks/setup-chunks.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: "Chained setup chunks"
author: "Nischal Shrestha"
output: learnr::tutorial
runtime: shiny_prerendered
description: >
This is a demo of chained setup chunks and how it can be used to build up / share code.
---

```{r setup, include = FALSE}
library(learnr)
d <- 3
```

# Addition

<!-- We'll start the setup chunk chain with a regular chunk dataA: -->

```{r setupA}
a <- 5
```

<!-- Note: we use `exercise.setup` to chain setup chunks. In the case of an exercise serving as a setup chunk, the pre-filled code will be used as the setup code. -->

<!-- We start with a simple single, setup chunk for dataB depending on dataA. This is the familiar setup workflow for an exercise. -->

```{r setupB, exercise.setup = "setupA"}
b <- a + d
```

Result of x should be 9.

```{r ex1, exercise=TRUE, exercise.setup = "setupB"}
x = b + 1
```

<!-- Note: setup chunks can use the default value of the exercises. -->

Result of y should be 10.

```{r ex2, exercise=TRUE, exercise.setup = "ex1"}
y <- x + 1
```

Result of z should be 15.

```{r ex3, exercise=TRUE, exercise.setup = "ex1"}
z <- x + 6
```

0 comments on commit 128d531

Please sign in to comment.