-
-
Notifications
You must be signed in to change notification settings - Fork 995
Open
Labels
nextto consider for next releaseto consider for next release
Description
---
format:
html: default
docx: default
---
```{r}
data.frame(apples = 1, bananas = 2, carrots = 3) |>
knitr::kable() |>
kableExtra::add_header_above(c("fruits" = 2, " " = 1))
```This will throw an error in docx because knitr output will have some HTML dependencies passed by kableExtra and rmarkdown is being too protective by throwing an error.
Quarto has this special feature of knowing how to parse HTML table (https://quarto.org/docs/authoring/tables.html#html-tables) so it should be possible to support kableExtra output for non HTML format in quarto.
Maybe this is something to do directly in kableExtra knit_print method when in Quarto 🤔
This works
---
format:
docx: default
keep-md: true
---
```{r}
tab <- data.frame(apples = 1, bananas = 2, carrots = 3) |>
knitr::kable() |>
kableExtra::add_header_above(c("fruits" = 2, " " = 1))
```
```{r}
#| output: asis
#| echo: false
if (knitr::pandoc_to("docx")) {
as.character(tab) |> knitr::raw_html()
}
```And gt does not have this issue, possibly because it does not add HTML deps in the knitted output
so no error triggered
---
format:
docx: default
keep-md: true
---
```{r}
library(gt)
towny |>
dplyr::slice_max(population_2021, n = 5) |>
dplyr::select(
name, latitude, longitude,
ends_with("2016"), ends_with("2021")
) |>
gt() |>
tab_spanner(
label = "Population",
columns = starts_with("pop")
) |>
tab_spanner(
label = "Density",
columns = starts_with("den")
) |>
tab_spanner(
label = md("*Location*"),
columns = ends_with("itude"),
id = "loc"
)
```Lines 796 to 801 in 688b1cf
| # if this isn't html and there are html dependencies then flag an error | |
| if (!(is_pandoc_to_html(output_format$pandoc) || | |
| identical(tolower(xfun::file_ext(output_file)), "html"))) { | |
| if (has_html_dependencies(knit_meta)) { | |
| if (!isTRUE(front_matter$always_allow_html)) { | |
| stop2("Functions that produce HTML output found in document targeting ", |
Metadata
Metadata
Assignees
Labels
nextto consider for next releaseto consider for next release