-check results does not see objects in exercise-setup chunk on Rstudio Server

The following learnr tutorial using gradethis does not find object m (or x) in the prepare chunk.

  1. This happens consistently only on Rstudio Server when invoked as (learnr::run_tutorial("demo", "package")).
  2. On Rstudio Server, it works with Run Document but ONLY after clearing knitr cache. It does not work, If the tutorial is run the second time without clearin cache.
  3. On Windows 10 it always works when the tutorial is opened directly as an .Rmd (Run Document) or as part of a package (learnr::run_tutorial("demo", "package")).
---
title: "Demo tutorial"
tutorial:
  id: "demo"
  version: 1.0 
runtime: shiny_prerendered
output:
  learnr::tutorial 
---


```{r setup} 
suppressPackageStartupMessages(library(learnr))
suppressPackageStartupMessages(library(gradethis)) 
knitr::opts_chunk$set(echo = FALSE)
tutorial_options(exercise.checker = gradethis::grade_learnr) 
```

# Compute Mean 

```{r prepare-q1}
x <- 11:20
m <- mean(x)
```


```{r q1, exercise=TRUE,   exercise.setup = "prepare-q1"}
x
mean(x) 
```


```{r q1-check}
grade_result(
 pass_if(~ .result == m)
)
```

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.