当我将 rmarkdown 文档输出为 pdf 时,很长的注释不会换行。例如:
x = 1 + 1 #This is a comment that will be written super duper long to see if it wraps around the document or if it trails off.
当我将文档编织成pdf时,结果是注释从页面上消失并且没有环绕。
我研究了这个问题并尝试了两件事:
library(formatR)
我还尝试在代码块中使用带有长注释的库(formatR)以及该代码块中的“tidy = TRUE,tidy.opts = list(width.cutoff = 60)”选项。
knitr::opts_chunk$set(tidy.opts = list(width.cutoff = 60), tidy = TRUE)
第一个解决方案没有像我想要的那样包装评论。第二种解决方案包含长代码,但不包含代码的注释。我怎样才能把长评论也包装起来?
一种方法可能是将注释放在单独的行上,然后使用
formatR
就可以了:
---
title: "Long code comment wrapping"
output: pdf_document
---
```{r setup, include=FALSE}
library(formatR)
knitr::opts_chunk$set(tidy.opts = list(width.cutoff = 80), tidy = TRUE)
```
```{r}
x = 1 + 1
# This is a comment that will be written super duper long to see if it wraps around the document or if it trails off.
```
这会导致: