2015-04-06 138 views
0

使用和knitr生成pdf文件時,如何避免R控制檯輸出文本溢出到邊距?例如,使用R markdown和knitr時避免將文本溢出到頁邊距

--- 
title: "Illustration" 
author: "Temp" 
date: "Monday, April 06, 2015" 
output: pdf_document 
--- 

Spilling of R output. 

```{r} 
library("tm") 
data("acq") 
str(acq) 
``` 
+0

您可以設置打印輸出的寬度。 – 2015-04-06 12:37:39

+0

查看knitr選項:http://yihui.name/knitr/options/ – 2015-04-06 12:46:46

+0

@RomanLuštrik用'''{r set-options,cache = FALSE}調整寬度 options(width = 50) rnorm 100) data(「tm」) data(「acq」) str(acq) ''' 但是調整隻發生在'rnorm(100)'上。它被'str(acq)'忽略。 – Crops 2015-04-07 05:15:56

回答

1

我已經找到了我的解決方法是使用widthstrict.width選項來str()function最一致的方式。 width選項指定要使用的頁面寬度,並應從寬度的活動選項()設置繼承。但是,我並不總是認爲這是一致的。 strict.width允許您控制如何處理多餘文本(剪切,包裝)。

--- 
title: "Illustration" 
author: "Temp" 
date: "Monday, April 06, 2015" 
output: pdf_document 
--- 

Spilling of R output. 

```{r} 
library("tm") 
data("acq") 
str(acq,width=80,strict.width="cut") 
```