No word wrap in flextable when printing to Word document
05:12 12 Dec 2019

I want to have flextables in a word document where I have linebreaks in some cells. My data is like in the following example:

Flexiris <-
  iris %>% 
  setDT %>% 
  .[, Species := str_replace_all(Species, "[aeiou]", "\n")]

> head(Flexiris)
   Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
1:          5.1         3.5          1.4         0.2 s\nt\ns\n
2:          4.9         3.0          1.4         0.2 s\nt\ns\n
3:          4.7         3.2          1.3         0.2 s\nt\ns\n
4:          4.6         3.1          1.5         0.2 s\nt\ns\n
5:          5.0         3.6          1.4         0.2 s\nt\ns\n
6:          5.4         3.9          1.7         0.4 s\nt\ns\n

Now I convert the data.frame to a huxtable (yes, it has to be in my case) and then to flextable.

Flexiris <- Flexiris %>% 
  as_hux %>% 
  as_FlexTable

The output is shown perfectly in the RStudio console. Then I print the output into a word document:

Document <- read_docx("XXXXX.docx")

Document %>% 
  body_add_par("New flextable") %>% 
  body_add_flextable(value = Flexiris)

print(Document, target = "Trash.docx")

In my Word document it looks like this: enter image description here

The problem isn't that the remaining text is missing but there is no word wrap in the table in the document. What can I do?

r ms-word formatting r-flextable