当我在 R 块标头中插入长标题等内容时,如果能够将标头拆分为多行,那就太好了。
有什么简单的方法可以做到这一点吗?
E.g.:
```{r, echo=FALSE, warning=FALSE,
fig.cap="Here is my really long caption. It'd be nice to split this and other portions across lines"}
print(plot(x=runif(100),y=runif(100)))
```
不可以,您不能在块选项中插入换行符。从手册 http://yihui.name/knitr/options/:
chunk选项必须写成一行;块选项内不允许换行
但是,如果您迫切希望在编辑器中进行整齐的格式设置,您可以通过附加变量绕道而行,但这会使代码大大膨胀:
---
output:
pdf_document:
fig_caption: yes
---
```{r}
mycaption <- "This is my
very long caption
that spans over
several lines.
(in the editor)"
```
```{r, fig.cap = mycaption}
plot(1)
```
随着选项eval.after
甚至可以定义mycaption
在使用它作为选项值的块中:
---
output:
pdf_document:
fig_caption: yes
---
```{r}
library(knitr)
opts_knit$set(eval.after = "fig.cap")
```
```{r, fig.cap = mycaption}
mycaption <- "This is my
very long caption
that spans over
several lines.
(in the editor)"
plot(1)
```
(我认为问题是关于如何code看起来(在编辑器中)不是关于换行符output.)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)