extract_body {gt} | R Documentation |
Extract the table body from a gt object
Description
We can extract the body of a gt table, even at various stages of its
rendering, from a gt_tbl
object using extract_body()
. By default, the
data frame returned will have gone through all of the build stages but we
can intercept the table body after a certain build stage. Here are the eight
different build stages and some notes about each:
-
"init"
: the body table is initialized here, entirely withNA
values. It's important to note that all columns of the are of thecharacter
type in this first stage. And all columns remain in the same order as the input data table. -
"fmt_applied"
: Any cell values that have had formatting applied to them are migrated to the body table. All other cells remain asNA
values. Depending on theoutput
type, the formatting may also be different. -
"sub_applied"
: Any cell values that have had substitution functions applied to them (whether or not they were previously formatted) are migrated to the body table or modified in place (if formatted). All cells that had neither been formatted nor undergone substitution remain asNA
values. -
"unfmt_included"
: All cells that either didn't have any formatting or any substitution operations applied are migrated to the body table.NA
values now become the string"NA"
, so, there aren't any true missing values in this body table. -
"cols_merged"
: The result of column-merging operations (throughcols_merge()
and related functions) is materialized here. Columns that were asked to be hidden will be present here (i.e., hiding columns doesn't remove them from the body table). -
"body_reassembled"
: Though columns do not move positions rows can move to different positions, and this is usually due to migration to different row groups. At this stage, rows will be in the finalized order that is seen in the associated display table. -
"text_transformed"
: Varioustext_*()
functions in gt can operate on body cells (now fully formatted at this stage) and return transformed character values. After this stage, the effects of those functions are apparent. -
"footnotes_attached"
: Footnote marks are attached to body cell values (either on the left or right of the content). This stage performs said attachment.
Usage
extract_body(
data,
build_stage = NULL,
output = c("html", "latex", "rtf", "word")
)
Arguments
data |
The gt table data object
This is the gt table object that is commonly created through use of the
|
build_stage |
The build stage of the formatted R data frame
When a gt undergoes rendering, the body of the table proceeds through
several build stages. Providing a single stage name will yield a data frame
that has been extracted after completed that stage. Here are the build
stages in order: (1) |
output |
Output format
The output format of the resulting data frame. This can either be
|
Value
A data frame or tibble object containing the table body.
Function ID
13-7
Function Introduced
v0.10.0
(October 7, 2023)
See Also
Other table export functions:
as_gtable()
,
as_latex()
,
as_raw_html()
,
as_rtf()
,
as_word()
,
extract_cells()
,
extract_summary()
,
gtsave()