Using R code in a Word document

What is the best way to paste an R code into a word document? So, it looks nice and neat. Many Thanks for your help

I would use a mono space font like Courier for the code. That gives it a code-like appearance.

My favorite monospaced font is Lucida Console. But lots of differing tastes
Some popular monospaced fonts are shown here

If you're trying to get R output in to Word, you might also be interested in the Word output format for Rmarkdown. You can read about it in the Rmarkdown book here https://bookdown.org/yihui/rmarkdown/word-document.html or read through a worked example here https://rmarkdown.rstudio.com/articles_docx.html

2 Likes

Additionally to the previous made comments you can also define a format style sheet entry in the list of existing style sheet entries inside Word which formats if choosed the already copied text as you like, f.e.:

  • indented
  • background colour
  • font
  • size
    Big advantage for you as a Word user: Those marked entries can be titled and also automated inserted into a table of contents (together with their titles).

So I think the answer of your questions is a bit related to your choice of which leading word processing program you want to use and what you're aiming for iwth the result at the end of the day.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.