I have been looking for a way to write R-generated reports to Microsoft
Word documents. In the past, I used the package R2wd, but for some reason
I haven't been able to get it to work on my current set up.
R version 2.15.0 (64-bit)
Windows 7 Enterprise - Service Pack 1
Microsoft Office Professional Plus 2010 - Word version
14.0.6123.5001 (32-bit)
I gave the package SWord a try, too. Also, no luck.
But, I just recently ran across the package rtf, and it serves my needs
quite well. Since some of you may find yourself in a similar situation, I
thought I'd spread the "word" (ha!) about rtf.
Below is some introductory code based on examples in
http://cran.r-project.org/web/packages/rtf/vignettes/rtf.pdf
Give it a try. You may like it!
Jean
`·.,, ><(((º> `·.,, ><(((º> `·.,, ><(((º>
Jean V. Adams
Statistician
U.S. Geological Survey
Great Lakes Science Center
223 East Steinfest Road
Antigo, WI 54409 USA
http://www.glsc.usgs.gov
library(rtf)
rtf <- RTF("rtf_vignette.doc", width=8.5, height=11, font.size=10,
omi=c(1, 1, 1, 1))
addHeader(rtf, title="This text was added with the addHeader() function.",
subtitle="So was this.")
addParagraph(rtf, "This text was added with the addParagraph() function.
It is a new self-contained paragraph. When Α is greater than
β, then γ is equal to zero.\n")
startParagraph(rtf)
addText(rtf, "This text was added with the startParagraph() and addText()
functions. You can insert ")
addText(rtf, "styled ", bold=TRUE, italic=TRUE)
addText(rtf, "text this way. But, you must end the paragraph manually
with the endParagraph() function.\n")
endParagraph(rtf)
increaseIndent(rtf)
addParagraph(rtf, paste(rep("You can indent text with the increaseIndent()
function.", 4), collapse=" "))
addNewLine(rtf)
decreaseIndent(rtf)
addParagraph(rtf, paste(rep("And remove the indent with the
decreaseIndent() function.", 4), collapse=" "))
addNewLine(rtf)
addNewLine(rtf)
addParagraph(rtf, "Table 1. Table of the iris data using the addTable()
function.\n")
tab <- table(iris$Species, floor(iris$Sepal.Length))
names(dimnames(tab)) <- c("Species", "Sepal Length")
addTable(rtf, tab, font.size=10, row.names=TRUE, NA.string="-",
col.widths=c(1, 0.5, 0.5, 0.5, 0.5) )
newPlot <- function() {
par(pty="s", cex=0.7)
plot(iris[, 1], iris[, 2])
abline(h=2.5, v=6.0, lty=2)
}
addPageBreak(rtf)
addPlot(rtf, plot.fun=newPlot, width=5, height=5, res=300)
addNewLine(rtf)
addParagraph(rtf, "Figure 1. Plot of the iris data using the addPlot()
function.\n")
addNewLine(rtf)
addNewLine(rtf)
addSessionInfo(rtf)
done(rtf)
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.