gt_tbl <- gt(exibble, rowname_col = "row", groupname_col = "group")The extract_cells() function
Let’s create a gt table with the exibble dataset to use in the next few examples:
We can extract a cell from the table with the extract_cells() function. This is done by providing a column and a row intersection:
extract_cells(gt_tbl, columns = num, row = 1)[1] "1.111e-01"
#> [1] "1.111e-01"Multiple cells can be extracted. Let’s get the first four cells from the char column.
extract_cells(gt_tbl, columns = char, rows = 1:4)[1] "apricot" "banana" "coconut" "durian"
#> [1] "apricot" "banana" "coconut" "durian"We can format cells and expect that the formatting is fully retained after extraction.
gt_tbl |>
fmt_number(columns = num, decimals = 2) |>
extract_cells(columns = num, rows = 1)[1] "0.11"
#> [1] "0.11"