0

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
```
lz100
  • 6,990
  • 6
  • 29

1 Answers1

0

This is a bug, install the latest develop version of {learnr}

remotes::install_github("rstudio/learnr")

It has been fixed in this issue

lz100
  • 6,990
  • 6
  • 29