John J.
John J.

Reputation: 1716

how to use gt::as_word output in a quarto file

The {{gt}} package now includes a function as_word, which outputs the table as an OOXML string.

I would like to use this to insert tables into the word output of a Quarto document.

I thought this would work.

---
title: "Untitled"
format: docx
---


```{r}
library(gt)

gtcars %>%
  dplyr::select(mfr, model) %>%
  dplyr::slice(1:2) %>%
  gt() %>%
  tab_header(
    title = md("Data listing from **gtcars**"),
    subtitle = md("`gtcars` is an R dataset")
  ) %>%
  as_word()
```

But the word output is just the OOXML string, like this. How can I make the table appear as a table in the quarto word output? enter image description here

Upvotes: 2

Views: 1137

Answers (1)

Martin C. Arnold
Martin C. Arnold

Reputation: 9668

No need to print an OOXML string for this purpose I guess – it works with the print() method for docx output:

```{r, echo=F}
library(gt)
gtcars %>%
  dplyr::select(mfr, model) %>%
  dplyr::slice(1:2) %>%
  gt() %>%
  tab_header(
    title = "Data listing from gtcars",
    subtitle = "gtcars is an R dataset"
  )
```

enter image description here

(There's some trouble with the markdown code though, probably a bug. I've removed md().)

Upvotes: 1

Related Questions