Rmarkdown & {knitr}:列表中的代码块亮点?
Rmarkdown & {knitr}: code chunk highlights in lists?
我有一个 two-level 有序列表,输出与 相同。 我的输出很好,看起来应该如何。我的问题是正常的 'highlighting' 块消失了 8 个空格,并且 RMD 源不再 'recognizes' 这样的块。块前后的空白行也缩进了(我发现我必须这样做才能获得所需的输出)。
为了说明这一点,我分享了下面的图片。突出显示丢失,并且其他块中的相同光标位置在左下角的 line:character 旁边给出了一个小按钮,而不是“(顶级)”。如果我引入块缩进(从 8 个空格到 4 个),代码将不再与输出中的列表对齐。
有什么办法可以解决这个问题吗?没有任何运气在线搜索或浏览文档。 (如果有兴趣,示例来自 ISLR,第 2.4 节,练习 8。)
我发现如果我将代码的缩进保持在比相应文本多一个缩进级别,则一切都会很好地呈现:
1. One level of indention
* Two levels of indention
* Three levels of indention
* Four levels of indention
```{r,eval=FALSE}
Some("R code")
```
好的,成功了。出于某种原因,在 R Studio 中两次点击制表符(四个空格)会导致上述问题。我怀疑它与 R Studio 有关,而不是与 R Markdown 或 {knitr} 有关。解决方案是@Yihui ,并且依赖于使用 indent
参数。这将保持块的突出显示和识别,并保持输出中的所有内容对齐。
我从没想过要使用 indent
参数,因为它没有列在当前 R Markdown 参考指南 (here), and is only mentioned passively at the end of the Code Description section in the {knitr} chunk options (here) 的 {knitr} 块选项中。
我有一个 two-level 有序列表,输出与
为了说明这一点,我分享了下面的图片。突出显示丢失,并且其他块中的相同光标位置在左下角的 line:character 旁边给出了一个小按钮,而不是“(顶级)”。如果我引入块缩进(从 8 个空格到 4 个),代码将不再与输出中的列表对齐。
有什么办法可以解决这个问题吗?没有任何运气在线搜索或浏览文档。 (如果有兴趣,示例来自 ISLR,第 2.4 节,练习 8。)
我发现如果我将代码的缩进保持在比相应文本多一个缩进级别,则一切都会很好地呈现:
1. One level of indention
* Two levels of indention
* Three levels of indention
* Four levels of indention
```{r,eval=FALSE}
Some("R code")
```
好的,成功了。出于某种原因,在 R Studio 中两次点击制表符(四个空格)会导致上述问题。我怀疑它与 R Studio 有关,而不是与 R Markdown 或 {knitr} 有关。解决方案是@Yihui indent
参数。这将保持块的突出显示和识别,并保持输出中的所有内容对齐。
我从没想过要使用 indent
参数,因为它没有列在当前 R Markdown 参考指南 (here), and is only mentioned passively at the end of the Code Description section in the {knitr} chunk options (here) 的 {knitr} 块选项中。