Che*_*off 4 printing console r word-wrap pander
我正在尝试调整 R 将数据帧打印到控制台的方式。具体来说,我想打印一个数据框,以便列的文本在达到一定宽度后换行。理想情况下,我想要如下所示的东西:
v1 v2 v3
1 TRUE Some text TRUE
2 TRUE Some more text FALSE
3 TRUE This text wraps FALSE
after a certain
width
4 FALSE Even more text FALSE
5 TRUE More text TRUE
Run Code Online (Sandbox Code Playgroud)
这是一个 MWE:
data.frame(v1 = c(TRUE, TRUE, TRUE, FALSE, TRUE), v2 = c("Some text", "Some more text", "This text wraps after a certain width", "Even more text", "More text"), y = c(TRUE, FALSE, FALSE, FALSE, TRUE))
options(width=10)
Run Code Online (Sandbox Code Playgroud)
这就是我所在的地方:
看一下库pandoc.table中的函数pander。它似乎做了你想做的事情http://rapporter.github.io/pander/pandoc_table.html
library(pander)
m<-data.frame(v1 = c(TRUE, TRUE, TRUE, FALSE, TRUE), v2 = c("Some text", "Some more text", "This text wraps after a certain width", "Even more text", "More text"), y = c(TRUE, FALSE, FALSE, FALSE, TRUE))
pandoc.table(m, split.cells = c(5, 20, 5))
#>---------------------------
#> v1 v2 y
#>----- --------------- -----
#>TRUE Some text TRUE
#>
#>TRUE Some more text FALSE
#>
#>TRUE This text wraps FALSE
#> after a certain
#> width
#>
#>FALSE Even more text FALSE
#>
#>TRUE More text TRUE
#>---------------------------
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2392 次 |
| 最近记录: |