Brackets in .Rmd code blocks
Does it work without a space between the ``` and the {r}? It may be that the Rmd processor is getting confused about the spaces, but ignoring the bare r, and assuming the code is R by default.
The examples here don't have spaces:
https://rmarkdown.rstudio.com/lesson-3.html