I am making some R markdown documents for my stats class. I've noticed I get an error in some functions when I have a code block with {r} instead of just r. Like so...

``` r
this code will be fine

``` {r}
this code will have an error

When should I be using the brackets for codeblocks in .Rmd and when should I leave them out?


1 Answer 1


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:


  • $\begingroup$ Thank you I believe you may be right. I am having other problems with my code. $\endgroup$ Mar 5, 2021 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.