Indented code chunk not runnable in RStudio

Viewed 80

I am trying to include a code-chunk as part of a list in R markdown, and while it is recognized correctly on knit, RStudio no longer recognizes it as a code chunk. Take the following example:

1. List item 1

    a. Sub-list item A
    
        sub-paragraph 1
        
        sub-paragraph 2
       
        ```{r}
        prop <- function (x) {
          (x + 1)*(8 - x)
        }
        ```
       
        $\therefore f(X) = \frac{(x + 1)(8 - x)}{120}$

On knit, the code chunk is recognized, run, properly indented, and further paragraphs in the list are also recognized:

working example

However, in RStudio, the code chunk is no longer recognized:

rstudio error

Unindenting the chunk to either 2 tabs or 0 tabs lets the chunk be recognized, but also breaks the list:

working rstudio code not indented, further paragraphs not recognized as part of the list broken pdf

Is there a way to include a r chunk in a list such that it's recognized by RStudio, but also as a block in the list?

0 Answers
Related