[R] pretty display or print for data frames ?

Erik Iverson eiverson at NMDP.ORG
Wed Aug 12 16:18:01 CEST 2009


I sometimes use the View() (note the capital V) function to view long/wide data.frames. 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Leon Yee
Sent: Wednesday, August 12, 2009 2:12 AM
To: Patrick Connolly
Cc: r-help at r-project.org
Subject: Re: [R] pretty display or print for data frames ?

Patrick Connolly wrote:
> 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.)

Thanks, Patrick.  Printing wide is sometimes needed. options(width=120) 
just works, but I need to changed it back to 80 every time for normal 
printing. Sort of tedious.
I'm just curious why print.data.frame does not take an argument of 
width=120, just like in print.factor.

## S3 method for class 'factor':
print(x, quote = FALSE, max.levels = NULL,
       width = getOption("width"), ...)

Best wishes,
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.




More information about the R-help mailing list