Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当打印到控制台时,如何在R中的列中包装文本?_R_Printing_Console_Word Wrap_Pander - Fatal编程技术网

当打印到控制台时,如何在R中的列中包装文本?

当打印到控制台时,如何在R中的列中包装文本?,r,printing,console,word-wrap,pander,R,Printing,Console,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

我试图调整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
这里有一个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)
这就是我所处的位置:


查看
pander
库中的
pandoc.table
函数。它似乎在做你想做的事

库(pander)
m---------------------------
#>v1 v2 y
#>----- --------------- -----
#>有些文字是真的
#>
#>真的,还有一些文字是假的
#>
#>TRUE此文本包装为FALSE
#>过了一段时间
#>宽度
#>
#>FALSE甚至更多文本FALSE
#>
#>TRUE更多文本TRUE
#>---------------------------
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 
#>---------------------------