John Lawrence Aspden
John Lawrence Aspden

Reputation: 17470

How do I generate a document (.rtf, .doc, .odt) from R

what's the best way to generate a word-processor file (ideally as platform-independent as possible, but native Word formats will do), with images in it, from the statistical language R?

Upvotes: 18

Views: 5456

Answers (6)

Vincent Guyader
Vincent Guyader

Reputation: 3199

The better solution seems to be the officer package : https://cran.r-project.org/web/packages/officer/index.html

library(officer)
doc <- read_docx() %>%
body_add_par("A title", style = "heading 1") %>%
body_add_par("Hello world!", style = "Normal") %>%
body_add_par("centered text", style = "centered")
print(doc, target = "body_add_par.docx" )

Upvotes: 2

janattack
janattack

Reputation: 420

Also worth mentioning: the RTF package isn't as powerful as some of the other options, but it's got less of a learning curve.

Upvotes: 3

Matti Pastell
Matti Pastell

Reputation: 9283

Here is my solution. It uses Sweave with reStructuredText markup which allows easy generation of odf, Latex and HTML documents from a single source. See here for different writers included in docutils.

There is also rst2wordml writer that doesn't implement all the features of rest, but you may find it also useful. It works with the example from my blog (first link) if you remove the table of contents directive.

Upvotes: 4

Gavin Simpson
Gavin Simpson

Reputation: 174908

The standard Sweave engine is one option if you can handle LaTeX - but I guess that is stretching the "word-processor file" aspect just a touch! Alternatively, odfWeave is a related package providing a new engine for Sweave that will work with OpenOffice.org documents.

There are other options on the Reproducible Research Task View on CRAN, although some of the MS Office oriented options require Windows specific cruft.

Upvotes: 13

eliavs
eliavs

Reputation: 2356

how about the R2wd package?

Upvotes: 4

Demosthenex
Demosthenex

Reputation: 4451

I'd recommend Emacs Org-Mode with Org-Babel and R. It means you can do R as a part of a document using literate programming with professional output to PDF (via Latex).

See:

http://orgmode.org/worg/org-contrib/babel/uses.php

http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-R.php

Upvotes: 2

Related Questions