Skip to content

Instantly share code, notes, and snippets.

@briandk
Last active October 2, 2023 15:12
Show Gist options
  • Save briandk/2fee6e2216da971bff67f84deeb8fb4e to your computer and use it in GitHub Desktop.
Save briandk/2fee6e2216da971bff67f84deeb8fb4e to your computer and use it in GitHub Desktop.
Trying to create a reproducible example of a bug in the `gt` package for R.
---
title: "GT Quarto Split Table Bug Test"
format:
docx: default # renders fine
html: default # fails with error (see below)
pdf: default # fails with error (see below)
---
## Test Code
```{r}
# Rendering to docx works fine
# Rendering to html fails with: Error in `if (is.na(table_id)) ...`: ! argument is of length zero
# Rendering to pdf fails with: Error in `stop_if_not_gt_tbl()`: ! The `data` provided is not a `gt_tbl` object.
library(gt)
library(sessioninfo)
session_info()
mtcars |>
gt() |>
gt_split(col_slice_at = matches("disp"))
```
## Error Outputs for Non-docx Formats
### HTML Error
```
processing file: gt-quarto-split-table-bug.qmd
|................................... | 67% [unnamed-chunk-1]
Quitting from lines 12-24 [unnamed-chunk-1] (gt-quarto-split-table-bug.qmd)
Error in `if (is.na(table_id)) ...`:
! argument is of length zero
Backtrace:
1. global .main()
2. execute(...)
3. rmarkdown::render(...)
4. knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
5. knitr:::process_file(text, output)
...
17. evaluate:::evaluate_call(...)
21. knitr (local) value_fun(ev$value, ev$visible)
22. knitr (local) fun(x, options = options)
25. gt:::knit_print.gt_group(x, ...)
26. gt:::as.tags.gt_tbl(x, ...)
Execution halted
```
### PDF Error
```
processing file: gt-quarto-split-table-bug.qmd
|................................... | 67% [unnamed-chunk-1]
Quitting from lines 12-24 [unnamed-chunk-1] (gt-quarto-split-table-bug.qmd)
Error in `stop_if_not_gt_tbl()`:
! The `data` provided is not a `gt_tbl` object.
Backtrace:
1. global .main()
2. execute(...)
3. rmarkdown::render(...)
4. knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
5. knitr:::process_file(text, output)
...
21. knitr (local) value_fun(ev$value, ev$visible)
22. knitr (local) fun(x, options = options)
25. gt:::knit_print.gt_group(x, ...)
26. gt::as_latex(x)
27. gt:::stop_if_not_gt_tbl(data = data)
Execution halted
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment