[R] struggling with R2wd or SWord? Try rtf!

John C Nash nashjc at uottawa.ca
Fri Oct 12 16:52:25 CEST 2012


I recently gave a talk to the Ottawa PC Users Group about Sweave, knitR and odfWeave. The
last is sometimes cranky, but I've found I can use it for word-processing documents, and
if these are saved in odt format (open office), then odfWeave can process them to
"finalized" odt form.

Recognize this isn't exactly the answer you sought, but possibly it is helpful. If there
is interest, I can send the slides for the talk and some of the smaller examples (a couple
are book length from knitR).

JN


On 10/12/2012 06:00 AM, r-help-request at r-project.org wrote:
> Message: 57
> Date: Thu, 11 Oct 2012 14:26:15 -0500
> From: Jean V Adams <jvadams at usgs.gov>
> To: r-help at r-project.org
> Subject: [R] struggling with R2wd or SWord?  Try rtf!
> Message-ID:
> 	<OF44F33EF2.95339A09-ON86257A94.00697515-86257A94.006ACB54 at usgs.gov>
> Content-Type: text/plain
> 
> 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]]
> 
> 
> 
> ------------------------------




More information about the R-help mailing list