Skip to content

Instantly share code, notes, and snippets.

@elipousson
Created November 21, 2023 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elipousson/e6741d31d7ae654e65219c543ebf7f59 to your computer and use it in GitHub Desktop.
Save elipousson/e6741d31d7ae654e65219c543ebf7f59 to your computer and use it in GitHub Desktop.
---
title: "gt table list multi-format knit"
format:
html: default
pdf: default
---
```{r}
library(gt)
nested_mtcars <- dplyr::nest_by(mtcars, cyl, .keep = TRUE)
tbl_list <- purrr::map(
nested_mtcars$data,
\(x) {
gt(x)
}
)
```
```{r}
#| results: asis
for (i in seq_along(tbl_list)) {
if (knitr::is_latex_output()) {
structure(
cat(gt::as_latex(tbl_list[[i]])),
class = "knit_asis"
)
} else {
print(tbl_list[[i]])
}
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment