0

When displaying output of an R Notebook, a text output will be displayed in its entirety. Is there a way to display only the first part of the text output, to get the "gist" of what is being output?

As an example, the output below shows a block of text. I realize the print() command does not know what should be displayed. However, in displaying an R Notebook, I'd like to avoid text outputs that are multiple pages long. Can the text output block be limited to a certain size.

enter image description here

Adam_G
  • 7,337
  • 20
  • 86
  • 148
  • 1
    How is the `print()` function going to magically know what parts you want to see and what parts you don't want to see? – hrbrmstr Jan 02 '17 at 13:26
  • I doubt it will. I'd just like the R notebook to display a limited window of text, so that when the notebook is displayed, there aren't, e.g., 3 pages of text output. – Adam_G Jan 02 '17 at 13:39
  • 1
    File a feature request on RStudio's support forum. It's going to be a chunk- or notebook-specific setting they'll add. – hrbrmstr Jan 02 '17 at 13:42
  • 1
    `print(object, max=SOME_NUMBER_OF_LINES)` will work provided `object`'s `print` method honors `max` (`summary`'s does). – hrbrmstr Jan 02 '17 at 13:45

1 Answers1

-2

I am not sure what you meant by 'gist', as summary already gives gist of the dataframe... but here are various commands to see some of dataset.

> summary(mtcars[1])
      mpg       
 Min.   :10.40  
 1st Qu.:15.43  
 Median :19.20  
 Mean   :20.09  
 3rd Qu.:22.80  
 Max.   :33.90  
> str(summary(mtcars))
 'table' chr [1:6, 1:11] "Min.   :10.40  " "1st Qu.:15.43  " ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:6] "" "" "" "" ...
  ..$ : chr [1:11] "     mpg" "     cyl" "     disp" "      hp" ...
> head(summary(mtcars),1)
      mpg             cyl             disp             hp       
 Min.   :10.40   Min.   :4.000   Min.   : 71.1   Min.   : 52.0  
      drat             wt             qsec             vs        
 Min.   :2.760   Min.   :1.513   Min.   :14.50   Min.   :0.0000  
       am              gear            carb      
 Min.   :0.0000   Min.   :3.000   Min.   :1.000  
> tail(summary(mtcars),1)
      mpg             cyl             disp             hp       
 Max.   :33.90   Max.   :8.000   Max.   :472.0   Max.   :335.0  
      drat             wt             qsec             vs        
 Max.   :4.930   Max.   :5.424   Max.   :22.90   Max.   :1.0000  
       am              gear            carb      
 Max.   :1.0000   Max.   :5.000   Max.   :8.000  
> summary(mtcars)[,1]

"Min.   :10.40  " "1st Qu.:15.43  " "Median :19.20  " "Mean   :20.09  " 

"3rd Qu.:22.80  " "Max.   :33.90  " 

> summary(mtcars)[1,]
               mpg                cyl               disp                 hp 
 "Min.   :10.40  "  "Min.   :4.000  "  "Min.   : 71.1  "  "Min.   : 52.0  " 
              drat                 wt               qsec                 vs 
 "Min.   :2.760  "  "Min.   :1.513  "  "Min.   :14.50  " "Min.   :0.0000  " 
                am               gear               carb 
"Min.   :0.0000  "  "Min.   :3.000  "  "Min.   :1.000  " 
xosp7tom
  • 2,131
  • 1
  • 17
  • 26