2017-05-24 2 views
1

Ich versuche, die Art und Weise einzustellen, wie R einen Datenrahmen an die Konsole druckt. Insbesondere möchte ich einen Datenrahmen so drucken, dass der Text für eine Spalte nach Erreichen einer bestimmten Breite umbrochen wird. Idealerweise möchte ich etwas, das wie folgt aussieht:Wie wird Text innerhalb einer Spalte in R eingefügt, wenn auf der Konsole gedruckt wird?

 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 

Hier ein MWE ist:

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) 

Hier ist, wo ich bin:

enter image description here

Antwort

2

am Werfen Sie einen Blick pandoc.table Funktion in der pander Bibliothek. Es scheint zu tun, was Sie sind nach 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 
#>--------------------------- 
Verwandte Themen