4

I am trying to include a table in a Word document but with no results. What I get in the resulting document is just a text list of the elements of the table including column names.

My code is organized in two scripts:

Script calling Markdown file KG-report.Rmd

rmarkdown::render("KG-report.Rmd", params = list(
    pest.name = pest.name),
    output_file = paste0("Report-", pest.name, ".docx")

Markdown script KG-report.Rmd

---
title: "Some title"
author: "me"
date: "`r Sys.Date()`"
output:
  officedown::rdocx_document:
    reference_docx: Simple_master_template_opinions.docx
    tables:
      style: Table
params: 
  pest.name: "Default pest"
---

```{r process-map, echo=FALSE, warning=FALSE, message=FALSE, fig.keep='all'}
# create and check directories
  source("R_scripts\\PEST.PROFILE.check.pest.directories.r", local = knitr::knit_global())
  
  # download distribution tables or load reviewed distribution table
  source("R_scripts\\PEST.PROFILE.web.EPPO.distribution.table.r", local = knitr::knit_global())

  knitr::kable(pest.kg.table)

etc...

After many tests and after following suggestions on word formatting (e.g. here) which did not solve the issue, it looks like the problem is related to looping on

rmarkdown::render()

If I do not use it the table is printed.... Is there any known issue about this or am I just using it in the wrong way? Thank you

UPDATE - SOLUTION FOUND

In the end I was able to find a solution. It looked like the kable function was printing a html table in the word file which resulted in text with no table formatting. Adding the argument format = "pipe" solved the issue.

Maio
  • 41
  • 3
  • 2
    Hey, thanks for this @Maio. I was having a similar problem. I was knitting to PDF, and when I knit directly from the .Rmd, my `kable` formatted tables showed up, but when the same document was knit from a call to `rmarkdown::render()`, the tables actually just straight-up disappeared. For me, I had to put `format = "latex"` inside the call to `kable`, and they magically reappeared. – Nova Jul 06 '21 at 12:15
  • 1
    Thanks @Maio for the solution and @Nova for where to put the solution. Specifically, `kable(..., format = "pipe")` solved the issue for me. – HBat Nov 20 '21 at 20:11

0 Answers0