R to Word, revisited
[This article was first published on Realizations in Biostatistics, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
In a previous post (a long time ago) I discussed a way to get a R data frame into a Word table. The code in that entry was essentially a brute force way of wrapping R data in RTF code, but that RTF code was the bare minimum. There was no optimization of widths, or borders, or anything like that.Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
There are a couple of other ways I can think of:
- Writing to CSV, then opening in MS Excel, then copying/pasting into Word (or even saving in another format)
- Going through HTML to get to Word (for example, the R2HTML package)
- Using a commercial solution such as Inference for R (has this been updated since 2009?!)
- Using Statconn, which seems broken in the later versions of Windows and is not cross platform in any case
- Going through LaTeX to RTF
- Use cat statements and the latex command from the Hmisc package (included with every R installation) or xtable package (downloadable from CRAN) to create a LaTeX document with the table.
- Call the l2r command included with the LaTeX2RTF installation. (This requires a bit of setup, see below.)
- Open up the result in Word and do any further manipulation.
I must admit, though, here is one area where SAS blows R away. With the exception of integration into LaTeX, and some semisuccessful integration with Excel through the Statconn project, R’s reporting capabilities in terms of nicely formatted output is seriously outpaced by SAS ODS.
To leave a comment for the author, please follow the link and comment on their blog: Realizations in Biostatistics.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.