[R] pretty display or print for data frames ?

Patrick Connolly p_connolly at slingshot.co.nz
Wed Aug 12 08:46:09 CEST 2009

On Wed, 12-Aug-2009 at 12:38PM +0800, Leon Yee wrote:

> Hi, all
>     I have a question of adjusting the output of a data frame with many  
> columns. By default, print() will print out several columns according to  
> the window size, and then it scrolls down and print out left columns.  
> How can I make it print all the columns in the same line?
>     I found options(width=80 or 120 or whatever) will the change the  
> behavior of print() and got the effect what I want, but using a  
> parameter directly doesn't work: print(x, width=xxx).
>     Can anyone help me out? thanks.

This will get it on one line.

options(width=120); print(x)

I'm not sure what your main objective is so that might be of no use.
If it's something you do often, you could make a little function that
takes the name of the dataframe and the width you'd like it printed.
You could even have the function put the width back to the initial
setting.  (Generally speaking, printing very wide gets messy, so
there's good reason why you might just want to do that.)


> Regards,
> Leon
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

   ___    Patrick Connolly   
 {~._.~}                   Great minds discuss ideas    
 _( Y )_  	         Average minds discuss events 
(:_~*~_:)                  Small minds discuss people  
 (_)-(_)  	                      ..... Eleanor Roosevelt

More information about the R-help mailing list