Reputation: 267
I have a two-level ordered list, and the output is identical to this post. My output is fine and looks how it should. My issue is the normal 'highlighting' of chunks disappears with 8 spaces, and the RMD source no longer 'recognizes' the chunks as such. The blank lines before and after the chunks are also indented (I found that I had to do this to get the desired output).
To illustrate this, I'm sharing the image below. The highlight is missing, and that same cursor position in other chunks gives a little button next to line:character in the bottom left rather than '(Top Level)'. If I bring the chunk indention in (from 8 spaces to 4) the code no longer lines up with the list in the output.
Is there any way to remedy this? Haven't had any luck searching online or going through the documentation. (If interested, the example comes from ISLR, Section 2.4, Exercise 8.)
Upvotes: 0
Views: 1950
Reputation: 267
Ok, got it working. For some reason hitting tab (four spaces) twice in R Studio causes the issue above. I suspect it has something to do with R Studio rather than R Markdown or {knitr}. The solution is this response by @Yihui, and relies on using the indent
parameter. That will keep the highlight and recognition of the chunk as well as keeping everything aligned in the output.
I never thought to use the indent
parameter as it's not listed in the {knitr} chunk options in the current R Markdown Reference Guide (here), and is only mentioned passively at the end of the Code Description section in the {knitr} chunk options (here).
Upvotes: 3
Reputation: 10167
I find that if I keep the indention of the code at one more indent level that the corresponding text, everything renders nicely:
1. One level of indention
* Two levels of indention
* Three levels of indention
* Four levels of indention
```{r,eval=FALSE}
Some("R code")
```
Upvotes: 2