[R] Printing to screen a matrix or data.frame in one chunk (not splitting columns)
Martin Maechler
maechler at stat.math.ethz.ch
Fri May 15 18:42:34 CEST 2009
>>>>> "AC" == Adrián Cortés <adrcort at gmail.com>
>>>>> on Fri, 15 May 2009 08:58:04 -0700 writes:
AC> Hello,
AC> I saw this nice trick I want to replicate but I lost the source and I hope
AC> one of you can point me to the solution. My problem is that I don't know
AC> the correct words to query this.
AC> When I print to screen a matrix or data.frame the columns are split and
AC> printed below the previous ones; even though I have plenty of screen left.
AC> E.g.,
>> my_matrix = matrix(runif(30),nrow=3,ncol=10)
>> my_matrix
AC> [,1] [,2] [,3] [,4] [,5] [,6]
AC> [,7]
AC> [1,] 0.4979305 0.1155717 0.4484069 0.29986049 0.5427566 0.4324351
AC> 0.269171456
AC> [2,] 0.8405987 0.3605237 0.6615507 0.75305248 0.8569482 0.3401004
AC> 0.192526423
AC> [3,] 0.5608779 0.3953941 0.9995035 0.03141064 0.7985053 0.4903582
AC> 0.000490054
AC> [,8] [,9] [,10]
AC> [1,] 0.1402751 0.2852381 0.98816751
AC> [2,] 0.8337806 0.7322920 0.17505541
AC> [3,] 0.5414113 0.4668012 0.04420137
AC> So there is a way to resize the space for printing so that everything in
AC> printed in one chunk.
options(width = 100) # or whatever.
---
For ESS users,
this option is set to the "correct" value, when R is started.
If later, the emacs window is resized,
you can automatically set the width to the current buffer
("window") size, by
M-x ess-execute-screen-options
or, for everyone here who has
(add-hook 'ess-mode-hook 'ess-add-MM-keys)
(add-hook 'inferior-ess-mode-hook 'ess-add-MM-keys)
in their ~/.emacs equivalent, it's a simple
"C-c w" ('w' for 'width') to adapt the R option to the emacs
window size.
Martin Maechler,
ETH Zurich
More information about the R-help
mailing list