Search code examples
r-markdownstan

RMarkdown not rendering Stan code chunk as code


When I knit the following RMarkdown document:


title: "Reprex"
author: "Jeremy Colman"
date: "17/07/2018"
output:
  html_document: default
  pdf_document: default
  word_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


 ```{stan, output.var='priors', eval = FALSE, tidy = FALSE}

parameters {
  real<lower = 0>  qtilde1;

}

model {
  qtilde1 ~ gamma(38.9, 0.67);

}

```

The Stan code chunk is rendered as ordinary text, including the three reverse single quotes and word stan from the chunk header. I cannot show that in this post because stackoverflow tells me, correctly but unhelpfully, "Your post appears to contain code that is not properly formatted as code". That sums up my problem!

Code chunks in R are rendered correctly.


Solution

  • Your

     ```{stan output.var='priors', eval = FALSE, tidy = FALSE}
    

    needs to be flush-left, but you have a leading space before the ```