Search code examples
rr-markdownrstudiotibblequarto

In RStudio, how to print tibble in quarto/rmarkdown chunk as in console?


When editing quarto/rmarkdown documents, I would like RStudio to display inline tibbles the same way as it does in the console, instead of the paginated default printing.

Instead of this:

Default printing of tibbles in RStudio IDE

I would much prefer the output from the console:

# A tibble: 150 × 5
   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
          <dbl>       <dbl>        <dbl>       <dbl> <fct>  
 1          5.1         3.5          1.4         0.2 setosa 
 2          4.9         3            1.4         0.2 setosa 
 3          4.7         3.2          1.3         0.2 setosa 
 4          4.6         3.1          1.5         0.2 setosa 
 5          5           3.6          1.4         0.2 setosa 
 6          5.4         3.9          1.7         0.4 setosa 
 7          4.6         3.4          1.4         0.3 setosa 
 8          5           3.4          1.5         0.2 setosa 
 9          4.4         2.9          1.4         0.2 setosa 
10          4.9         3.1          1.5         0.1 setosa 
# … with 140 more rows
# ℹ Use `print(n = ...)` to see more rows

I have tried setting #| results: asis and changing the df-print option in the yaml, but that only affects the rendered document. I could make RStudio show chunk output in the console instead, but I would prefer if i could keep it inline.


Solution

  • You could use the option paged.print=FALSE in your chunk which will turn of paged tables like this:

    ---
    format: html
    ---
    
    ```{r paged.print=FALSE}
    library(tibble)
    as_tibble(iris)
    ```
    

    Which outputs this in chunk:

    # A tibble: 150 × 5
       Sepal.Length Sepal.Width Petal.Length Petal.Width Species
              <dbl>       <dbl>        <dbl>       <dbl> <fct>  
     1          5.1         3.5          1.4         0.2 setosa 
     2          4.9         3            1.4         0.2 setosa 
     3          4.7         3.2          1.3         0.2 setosa 
     4          4.6         3.1          1.5         0.2 setosa 
     5          5           3.6          1.4         0.2 setosa 
     6          5.4         3.9          1.7         0.4 setosa 
     7          4.6         3.4          1.4         0.3 setosa 
     8          5           3.4          1.5         0.2 setosa 
     9          4.4         2.9          1.4         0.2 setosa 
    10          4.9         3.1          1.5         0.1 setosa 
    # … with 140 more rows
    # ℹ Use `print(n = ...)` to see more rows
    

    Check this document for more information and options in chunks.