I am building a learnr tutorial app to teach some statistical techniques. Ideally I would like to share variables between code chunks, but I believe I can create a work-around using "setup chunks".
I've tried using "Chained setup chunks" as per this website: https://rstudio.github.io/learnr/exercises.html, but I cannot get the chain to go more than one level before the variables are no longer recognized.
I have created a simple example to try to work out where my problem is but it still doesn't work. Code chunk b gives 4, but chunk c gives 'object y not found'. What am I missing here?
Please ignore the backslashes, they were only included for formatting.
---
title: "Tutorial"
output: learnr::tutorial
runtime: shiny_prerendered
---
```{r setup, include=FALSE}
library(learnr)
```
```{r a}
x <- 2
```
```{r b, exercise=TRUE, exercise.setup="a"}
y <- 2 * x
y
```
```{r c, exercise=TRUE, exercise.setup="b"}
y
```