gt
gt copied to clipboard
`gt_split()` with group/row labels
Prework
- [x] Read and agree to the code of conduct and contributing guidelines.
- [x] If there is already a relevant issue, whether open or closed, comment on the existing thread instead of posting a new issue.
Description
Unable to use gt_split() on tables with row groups or row labels.
Reproducible example
- [x] Post a minimal reproducible example so the maintainer can troubleshoot the problems you identify. A reproducible example is:
- [x] Runnable: post enough R code and data so any onlooker can create the error on their own computer.
- [x] Minimal: reduce runtime wherever possible and remove complicated details that are irrelevant to the issue at hand.
- [x] Readable: format your code according to the tidyverse style guide.
- Trying to split a table with row groups:
gtcars |>
dplyr::slice_head(n = 10) |>
dplyr::select(mfr, model, year, msrp) |>
gt(groupname_col = "mfr") |>
gt_split(row_every_n = 5)
produces the error:
Error in !is.null(group_id) && !has_two_col_stub && group_row_start == :
'length = 2' in coercion to 'logical(1)'
- Trying to split a table with row labels:
gtcars |>
dplyr::slice_head(n = 10) |>
dplyr::select(mfr, model, year, msrp) |>
gt(rowname_col= "mfr") |>
gt_split(row_every_n = 5)
produces the error:
Error in `table_body[[stub_var]]`:
! Can't extract column with `stub_var`.
✖ Subscript `stub_var` must be a location, not a character `NA`.
Expected result
I would have expected the table to split into 2 tables (would it be based on 5 rows of the body cells?), while retaining the group/row labels.
Very glad you caught this, thanks! Will fix this one soon.
I have a similar problem when having tables with merged cols:
Doesn't function properly with both cols_merge and gt_split; however, either of them individually works.
gtcars |>
dplyr::slice_head(n = 10) |>
dplyr::select(mfr, model, year, msrp) |>
gt() |>
cols_merge(
columns = c("mfr","model"),
pattern = "{1} ({2})"
) %>%
gt_split(col_slice_at = "year")
Error in `data_tbl[rows, columns]`:
! Can't subset columns that don't exist.
✖ Column `model` doesn't exist.