Sometimes you may want to see just a small portion of your input data. We can
use gt_preview() in place of gt() to get the first x rows of data and the
last y rows of data (which can be set by the top_n and bottom_n
arguments). It's not advised to use additional gt functions to further
modify the output of gt_preview(). Furthermore, you cannot pass a gt
object to gt_preview().
Arguments
- data
Input data table
obj:<data.frame>|obj:<tbl_df>// requiredA
data.frameobject or a tibble (tbl_df).- top_n
Top n rows to display
scalar<numeric|integer>// default:5The
top_nvalue will be used as the number of rows from the top of the table to display. The default,5, will show the first five rows of the table.- bottom_n
Bottom n rows to display
scalar<numeric|integer>// default:1The
bottom_nvalue will be used as the number of rows from the bottom of the table to display. The default,1, will show the final row of the table.- incl_rownums
Display row numbers
scalar<logical>// default:TRUEAn option to include the row numbers for
datain the table stub.
Details
By default, the output table will include row numbers in a stub (including a
range of row numbers for the omitted rows). This row numbering option can be
deactivated by setting incl_rownums to FALSE.
Examples
With three columns from the gtcars dataset, let's create a gt table
preview with the gt_preview() function. You'll get only the first five rows
and the last row.
gtcars |>
dplyr::select(mfr, model, year) |>
gt_preview()
See also
Other table creation functions:
gt()