如何正确设置渲染 Rmarkdown 为 pdf?

How to properly set rendering Rmarkdown to pdf?

我使用 Rmarkdown 生成报告,如果我的行太长,通常会在渲染后被剪掉。

有办法解决吗?

我附上截图以便更好地解释我的问题。

您可以使用块选项 tidy=TRUE 在代码中自动插入换行符。

---
output: pdf_document
---

```{r, tidy = TRUE}
c(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
```

换行符由 formatR::tidy_source() 插入。有关详细信息,请参阅 https://yihui.org/knitr/options/#code-decoration

chunk_content <- "c(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)"
formatR::tidy_source(text = chunk_content, width.cutoff = 30)
#> c(1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
#>     1, 2, 3, 4, 5, 6, 7, 8, 9,
#>     0, 1, 2, 3, 4, 5, 6, 7, 8,
#>     9, 0, 1, 2, 3, 4, 5, 6, 7,
#>     8, 9, 0)