248

tibble (previously tbl_df) is a version of a data frame created by the dplyr data frame manipulation package in R. It prevents long table outputs when accidentally calling the data frame.

Once a data frame has been wrapped by tibble/tbl_df, is there a command to view the whole data frame though (all the rows and columns of the data frame)?

If I use df[1:100,], I will see all 100 rows, but if I use df[1:101,], it will only display the first 10 rows. I would like to easily display all the rows to quickly scroll through them.

Is there either a dplyr command to counteract this or a way to unwrap the data frame?

2
  • 5
    View is unchanged with "tbl_df" objects. Apr 21, 2014 at 0:49
  • 11
    @G.Grothendieck Viewing is different than printing.
    – Meg
    Jan 17, 2017 at 22:32

7 Answers 7

Reset to default

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

292

You could also use

print(tbl_df(df), n=40)

or with the help of the pipe operator

df %>% tbl_df %>% print(n=40)

To print all rows specify tbl_df %>% print(n = Inf)

edit 31.07.2021: in > dplyr 1.0.0

Warning message:
`tbl_df()` was deprecated in dplyr 1.0.0.
Please use `tibble::as_tibble()` instead.

df %>% as_tibble() %>% print(n=40)

6
  • 35
    if you want don't want to worry about the value of n and you're already piping, you can use df %>% tbl_df %>% print(n = nrow(.))
    – ClaytonJY
    Aug 3, 2016 at 15:57
  • 21
    Extending @BLT's answer, you can set n = Inf to print all rows.
    – seasmith
    Feb 2, 2017 at 21:38
  • 11
    print (with a tibble) also has the width = and n_extra = options to control how many columns are printed, either directly or indirectly.
    – Zhe Zhang
    May 17, 2017 at 16:57
  • 3
    @ClaytonJY I've also found tbl_df %>% print(n = Inf) to work for this.
    – Dannid
    Nov 21, 2018 at 19:44
  • does anybody know whyprint(n = ...) turns on scientific notation in the tibble display?
    – Agile Bean
    Aug 1, 2019 at 9:53
99

You can use as.data.frame or print.data.frame.

If you want this to be the default, you can change the value of the dplyr.print_max option.

options(dplyr.print_max = 1e9)
2
  • 1
    After running this code, do you know how to disable it? Thanks.
    – ah bon
    Jan 6 at 9:21
  • 1
    @ahbon Run options(dplyr.print_max=NULL) (this is the default value for this option) Jun 1 at 17:45
80

The tibble vignette has an updated way to change its default printing behavior:

You can control the default appearance with options:

options(pillar.print_max = n, pillar.print_min = m): if there are more than n rows, print only the first m rows. Use options(pillar.print_max = Inf) to always show all rows.

options(pillar.width = n): use n character slots horizontally to show the data. If n > getOption("width"), this will result in multiple tiers. Use options(pillar.width = Inf) to always print all columns, regardless of the width of the screen.

examples

This will always print all rows:

options(pillar.print_max = Inf)

This will not actually limit the printing to 50 lines:

options(pillar.print_max = 50)

But this will restrict printing to 50 lines:

options(pillar.print_max = 50, pillar.print_min = 50)
4
  • 2
    This will change the default behavior for all tibbles. I was looking for a way to override the default constraint. print(n=100) appears to do what I want. (Summary tables from count(), for example, should display in their entirety, whereas I do want my data tables to be truncated.)
    – Dannid
    Oct 30, 2018 at 20:49
  • 2
    @dannid looks like you want the accepted answer, then.
    – BLT
    Oct 31, 2018 at 3:54
  • 1
    "As of tibble 3.1.0, printing is handled entirely by the pillar package." (From the "Printing tibbles" help file.) To control the default appearance with options you can use: options(pillar.print_max = n, pillar.print_min = m).
    – petzi
    Dec 16, 2021 at 11:26
  • 1
    @petzi amazing, thanks for flagging. I believe I've updated it to reflect the latest in the tibble vignette.
    – BLT
    Dec 17, 2021 at 18:22
7

As detailed out in the bookdown documentation, you could also use a paged table

mtcars %>% tbl_df %>% rmarkdown::paged_table()

This will paginate the data and allows to browse all rows and columns (unless configured to cap the rows). Example:

enter image description here

2
  • 2
    As described in that documentation: If the paged table is generated by a code chunk in an R Notebook, you can add the parameter rows.print=[n] to the chunk options to control the number of rows displayed per page. Sep 18, 2019 at 17:00
  • This is great for html output, but obviously won't work for pdf.
    – PatrickT
    Feb 10 at 7:24
2

I prefer to turn the tibble to data.frame. It shows everything and you're done

df %>% data.frame 
2

you can print it in Rstudio with View() more convenient:

df %>% View()

View(df)
0

If you want to use pipes and find yourself wanting to see the whole tibble a lot, here's a solution with a function showAll():

showAll<-function(tbl_df){
  print(tbl_df,n=nrow(tbl_df))
}

require(tibble)
#Truncated tibble (default)
mtcars %>% as_tibble()

#Full size tibble
mtcars %>% as_tibble() %>% showAll()
1
  • The really useful nugget in the center of that is the n argument to the print function.
    – Chris
    Feb 11 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.