Created
November 21, 2023 04:15
-
-
Save elipousson/e6741d31d7ae654e65219c543ebf7f59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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