Stavros Macrakis
2009-Nov-11 21:56 UTC
[R] Suppressing final spaces in data.frame printouts
When printing data.frames, R aligns columns by padding with spaces. For example, print(data.frame(x=c('a','bb','ccc')),right=FALSE) ? x 1 a? |------------------ vertical bar shows end of line 2 bb |------------------ vertical bar shows end of line 3 ccc|------------------ vertical bar shows end of line Is there some way to suppress the padding for the final column? I often have data frames which contain a handful of long strings in the final column which, when printed out, cause wraparound on all the rows, even those not containing long strings, something like this: print(data.frame(q=1:3,x=c('a','bb','this is a very long string')),right=FALSE) ? q x?????????????? | ????????? | 1 1 a?????????????? | ????????? | 2 2 bb????????????? | ????????? | 3 3 this is a very l| ong string| where I'd rather have print(data.frame(q=1:3,x=c('a','bb','this is a very long string')),right=FALSE) q x| 1 1 a| 2 2 bb| 3 3 this is a very l| ong string| I could of course write my own print function for this, but was wondering if there was a standard way of doing it. If not in R, perhaps there is some way to have ESS delete the final spaces? Thanks, -s
Richard M. Heiberger
2009-Nov-11 22:40 UTC
[R] Suppressing final spaces in data.frame printouts
Stavros Macrakis wrote:> I could of course write my own print function for this, but was > wondering if there was a standard way of doing it. If not in R, > perhaps there is some way to have ESS delete the final spaces? >ESS, or more precisely emacs, can handle that. Use the M-x toggle-truncate-lines command: Toggle whether to fold or truncate long lines for the current buffer. Rich