Display / print all rows of a tibble (tbl_df)

RDplyrOptionsDisplay

R Problem Overview


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?

R Solutions


Solution 1 - R

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)

Solution 2 - R

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)

Solution 3 - R

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)

Solution 4 - R

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

Solution 5 - R

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

df %>% data.frame 

Solution 6 - R

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

df %>% View()

View(df)

Solution 7 - R

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()

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZhe ZhangView Question on Stackoverflow
Solution 1 - RTimView Answer on Stackoverflow
Solution 2 - RVincent ZoonekyndView Answer on Stackoverflow
Solution 3 - RBLTView Answer on Stackoverflow
Solution 4 - RHolger BrandlView Answer on Stackoverflow
Solution 5 - RLeftyView Answer on Stackoverflow
Solution 6 - RAbdelali AmgharView Answer on Stackoverflow
Solution 7 - RmattadorView Answer on Stackoverflow