The following learnr
tutorial using gradethis
does not find object m
(or x
) in the prepare chunk.
- This happens consistently only on Rstudio Server when invoked as
(learnr::run_tutorial("demo", "package"))
. - 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.
- 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)
)
```