1

Is there a proper way/a command to copy the output of R and paste it in a Word document, without loosing the formatting? I already tried to put the next command at the beginning of my syntax:

sink("./output.txt", append = T) #write output to file output.txt

And I wrote the next command at the end of my syntax:

sink()   #stop recording

It gives me a text file (in R) with the results of my output, but when I paste it in a Microsoft Word document, I still loose the formatting.

Thank you

Phil
  • 7,287
  • 3
  • 36
  • 66
  • If you're familiar with R Markdown, the most straightforward way would be to have your workflow in R so you can easily create the report with tables embedded in one document. Barring that, you could have an R Markdown file output a word document and copy and paste the table from that. https://bookdown.org/yihui/rmarkdown/word-document.html – TrainingPizza Feb 17 '22 at 21:54
  • Package `DescTools` has functions to write R output to Word or Powerpoint documents. – dcarlson Feb 18 '22 at 05:02
  • @dcarlson could you prove an example? I can't find an easy to use function in the package – Herman Toothrot Jun 14 '22 at 15:50
  • I can't provide an example because I don't have a licensed copy of Microsoft Office which is required by `DescTools`. The manual page for the Powerpoint interface, including examples is at [DescTools](https://cran.r-project.org/web//packages/DescTools/DescTools.pdf) beginning on page 444 which includes examples. I do not think that R Markdown requires a licensed copy of Microsoft Office (page 23) so that is the better approach if you do not have the software. – dcarlson Jun 15 '22 at 00:31

0 Answers0