在 RStudio 中的 R markdown 中,如何防止源代码从 pdf 页面运行? [英] In R markdown in RStudio, how can I prevent the source code from running off a pdf page?
问题描述
我目前有一些看起来像这样的代码:
I currently have some code that looks like so:
```{r, tidy=TRUE}
plot(DT$age, DT$height, xlab = "Age of participant in Trials", ylab = "Height of participant in Trials")
```
现在,我的理解是,将 tidy
设置为 TRUE
会使得当我将代码编织在一起时,代码不会跑出页面并且会自行包装.但是,当我执行上述命令时,我仍然偶尔会运行源代码显示.是否有另一个函数可以保证代码的包装?谢谢!
Now, it was my understanding that setting tidy
to TRUE
would make it so that when I knit the code together, the code would not go running off the page and would wrap by itself. However, I sporadically still get run off source code displays when I do commands like the one above. Is there another function that would guarantee the wrapping of code? Thanks!
推荐答案
使用 tidy.opts
knitr 选项中的 width.cutoff
参数来指定输出宽度:
Use the width.cutoff
argument inside tidy.opts
knitr options to specify the output width :
```{r, tidy=TRUE, tidy.opts=list(width.cutoff=60)}
plot(DT$age, DT$height, xlab = "Age of participant in Trials", ylab = "Height of participant in trials")
```
您可以使用这样的块为整个文件全局定义此选项:
You can define this option globally for your whole file with a chunk like this :
```{r}
library(knitr)
opts_chunk$set(tidy.opts=list(width.cutoff=60),tidy=TRUE)
```
tidy.opts
选项被传递给进行整理的 formatR
包(如果我理解正确的话).关于 formatR
的深入信息可以在这里找到:
The tidy.opts
options are passed to the formatR
package which does the tidying (if I understand correctly). In-depth informations about formatR
can be found here :
这篇关于在 RStudio 中的 R markdown 中,如何防止源代码从 pdf 页面运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!