Hi! I am trying to following the quarto presentation tutorial for highlighting lines of code: Quarto – Revealjs
I can get the python syntax to render with code highlighting, but I am unable to do the same for R syntax. Is this possible to execute with R as well?
Below is a screenshot example .qmd, which yields the error shown.
The raw .qmd is below, but I couldn't get it to format correctly. Please let me know if you also have tips for formatting chunks/ minimal .qmd's in this forum for readability.
You encounter an issue because you are using a Quarto format specific option code-line-numbers in usual knitr chunk option syntax. Quarto chunk options have dash in their name and R does not support dash in variable name unless you add specific quote. So this would work
However, with Quarto, it is better to use the syntax using special comment #|, as it will be more portable between computation engine, and it is easier with Quarto specific options.
Thank you very much! I could tell something was off, but I could not find it in the documentation. Is it somewhere there that I missed? Or would it be worth submitting a documentation issue in the presentation guide line highlighting section, as all of the chunks demo python code?
The example in this case are all non-compute chunk. They are verbatim code chunks with a class set on them for highlighting language. If they were given for R it would be with your example
```{.r code-line-numbers="1"}
1
1:2
```
You would not use YAML chunk option in this case, as this is not a chunk to execute.
@cderv Thank you so much for all of these helpful explanations. I have one more follow up question.
I am having trouble finding documentation on the non-compute code chunks indicated by .r. Is this a quarto thing? An rmarkdown thing? Can you point me to any links?
R Markdown and Quarto will output that for you when you use eval = FALSE as only the source code will be included. However, you need computation engine in this case, whereas with the fenced class you don't need any engine.