开发者

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

what's the best way to generate a word-processor file (idea开发者_运维百科lly as platform-independent as possible, but native Word formats will do), with images in it, from the statistical language R?


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.


how about the R2wd package?


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.


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.


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


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" )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜