Display / print all rows of a tibble (tbl_df)
Solution 1
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
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
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. Useoptions(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
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:
Solution 5
you can print it in Rstudio with View() more convenient:
df %>% View()
View(df)
Related videos on Youtube
Zhe Zhang
Updated on December 18, 2021Comments
-
Zhe Zhang over 2 years
tibble
(previouslytbl_df
) is a version of a data frame created by thedplyr
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 usedf[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?
-
G. Grothendieck about 10 years
View
is unchanged with"tbl_df"
objects. -
Meg over 7 years@G.Grothendieck Viewing is different than printing.
-
-
ClaytonJY almost 8 yearsif you want don't want to worry about the value of
n
and you're already piping, you can usedf %>% tbl_df %>% print(n = nrow(.))
-
seasmith over 7 yearsExtending @BLT's answer, you can set
n = Inf
to print all rows. -
Zhe Zhang about 7 years
print
(with a tibble) also has thewidth =
andn_extra =
options to control how many columns are printed, either directly or indirectly. -
Dannid over 5 yearsThis 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 fromcount()
, for example, should display in their entirety, whereas I do want my data tables to be truncated.) -
BLT over 5 years@dannid looks like you want the accepted answer, then.
-
Dannid over 5 years@ClaytonJY I've also found
tbl_df %>% print(n = Inf)
to work for this. -
Agile Bean almost 5 yearsdoes anybody know why
print(n = ...)
turns on scientific notation in the tibble display? -
Arthur Small almost 5 yearsAs 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. -
stucash almost 3 yearsbear in mind that if you choose to do
print(n=nrow(.))
, you need to have an object in hand first; if you are retrieving data from remote data source (e.g. a database connection), you'll have to dodf <- tbl(conn, "db_name"); df %>% print(n=nrow(.))
. -
petzi over 2 years"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)
. -
BLT over 2 years@petzi amazing, thanks for flagging. I believe I've updated it to reflect the latest in the tibble vignette.
-
ah bon over 2 yearsAfter running this code, do you know how to disable it? Thanks.
-
PatrickT over 2 yearsThis is great for
html
output, but obviously won't work forpdf
. -
Chris over 2 yearsThe really useful nugget in the center of that is the n argument to the print function.
-
Patrick Coulombe about 2 years@ahbon Run
options(dplyr.print_max=NULL)
(this is the default value for this option)