rrscript

How do I tell summary to not wrap columns?


I am trying to get summary to not wrap its output. However, when I call summary with 5 columns of data, it places the 5th column on a separate row. I am hoping there is a way that's easier than manually printing iterating over the object returned by summary.

plotit.r

#!/usr/bin/Rscript
noneData <- read.csv("query.log", header=FALSE, sep="\t");
cnames = c( 'vids', 'partitions', 'localvert', 'remotevert',
                    'cachehits', 'responsetime' );
colnames(noneData) <- cnames;
cachenames = c('1', '2', '3', '4', '5');
responseCompare = data.frame(
   noneData$responsetime/1000000,
   noneData$responsetime/1000000,
   noneData$responsetime/1000000,
   noneData$responsetime/1000000,
   noneData$responsetime/1000000
   );
colnames(responseCompare) <- cachenames;
print("Response Times");
summary(responseCompare);

./plotit.r #output:

[1] "Response Times"
       1                  2                  3                  4         
 Min.   :   0.215   Min.   :   0.215   Min.   :   0.215   Min.   :   0.215
 1st Qu.: 395.202   1st Qu.: 395.202   1st Qu.: 395.202   1st Qu.: 395.202
 Median : 459.888   Median : 459.888   Median : 459.888   Median : 459.888
 Mean   : 466.726   Mean   : 466.726   Mean   : 466.726   Mean   : 466.726
 3rd Qu.: 530.122   3rd Qu.: 530.122   3rd Qu.: 530.122   3rd Qu.: 530.122
 Max.   :3275.916   Max.   :3275.916   Max.   :3275.916   Max.   :3275.916
       5          
 Min.   :   0.215 
 1st Qu.: 395.202 
 Median : 459.888 
 Mean   : 466.726 
 3rd Qu.: 530.122 
 Max.   :3275.916 

Solution

  • The options() function gives you a method of creating side-effects in the R console environment:

     names( options() )
     options(width=120) ; cat("Response Times"); summary(responseCompare)
    

    The print method will then only add "\n" when it reaches a "virtual end of page" at 120 total characters. It calculates the width of columns and only prints a batch of columns at a time.