RweaveRtf {rtfSweave}R Documentation

An Sweave driver for rich text format (RTF) documents

Description

An add-on driver to enable Sweave to process RTF documents

Usage

RweaveRtf()
RtangleRtf()
SweaveSyntaxRtf


Details

The Sweave function uses by default the RweaveLatex driver to process LaTeX documents. However, Sweave was designed to allow authors to write their own drivers. The rtfSweave driver documented here is essentially a copy of the RweaveLatex driver with some necessary changes to make it work for rich text format (RTF) documents.

RTF documents are plain text documents that have some similarities to LaTeX. For one thing, RTF documents can be opened and edited using Emacs or another text editor. While the RTF files written by Microsoft Word are difficult to read, without loss of functionality one can write very human-readable RTF documents which can be opened in Microsoft Word. One can write RTF documents with headings, subheadings, headers, footers, complex tables, figures, etc. It may be helpful to think of RTF as a text-based interface to nearly all of Microsoft Word's functionality.

My motivation for creating an RTF driver for Sweave was that my non-statistician colleagues, collaborators, and clients almost exclusively use Microsoft Word. Rather than converting a LaTeX report created with Sweave to RTF, it is arguably simpler to write the document in RTF directly, and use Sweave to create the final report which can be sent to colleagues as is or after saving in a native Microsoft Word format (e.g., *.doc or *.docx).

Important options for rtfSweave

png

The default for figures.

jpeg

JPEG figures are supported.

wmf

WMF figures are supported. This will work only on Windows as it relies on win.metafile. There is no checking whether the platform is actually Windows but there should be.

hex

This controls whether the figure is embedded into the RTF document as hexadecimal characters. The default is TRUE. If FALSE then the output file “includes” the file with an “INCLUDEPICTURE” RTF field instruction. This produces small files since the figures are not embedded but it takes some Word commands to convert the “included” picture into an embedded image.

resolution

While not specific to rtfSweave this options is used enough often. It controls the figure resolution and defaults to 300 dpi.

pointsize

Controls pointsize for the figures.

rtf.Schunk

RTF paragraph formatting commands for the R input and output. The default is Sweave like. Since the R input and output are part of the same paragraph (with lines broken by \line), this options controls formatting for both input and output.

rtf.Sinput

RTF text formatting commands for R input.

rtf.Soutput

RTF text formatting commands for R output.

results

Set this to "rtf" if the Soutput is “native” RTF code.

Weaving versus tangling and naming conventions

Documents written with RTF documentation chunks can be “weaved” to form an RTF report or “tangled” to extract the code chunks. A separate driver is needed for these two tasks as demonstrated in the examples.

Since Sweave provides Rweave() and Rtangle(), the respective drivers for RTF are named RweaveRtf() and RtangleRtf.

Note

This driver is unlikely to work with documents written directly in Microsoft Word and saved as RTF prior to processing with Sweave. The problem is that what might look like a valid code chunk on the screen will, once saved as RTF, end up with random linebreaks and a good bit of RTF markup in the actual text file.

The Microsoft WordPad program writes cleaner RTF and it may be relatively straightforward to update the rtfSweave driver to remove the hidden RTF commands that get added to a code chunk when the file is saved and then parse the code chunk. In other words, it may not be possible to “sanitize” a code chunk saved in Word but it should be pretty easy to sanitize a code chunk saved in WordPad.

Author(s)

Stephen Weigand Weigand.Stephen@mayo.edu adapted the code of Friedrich Leisch and others

See Also

Sweave

Examples

testfilepath <- system.file("examples", "rtfSweave-test-1.rtf",
                            package = "rtfSweave")

## 'weave' to create the document
##
## 'syntax' argument can be unspecified since per its help
## Sweave can find syntax objects matching pattern 'SweaveSyntax.*'
Sweave(testfilepath, driver = RweaveRtf, syntax = SweaveSyntaxRtf,
       output = tempfile(fileext = ".rtf"))


## 'tangle' to extract R code chunks.
Sweave(testfilepath, driver = RtangleRtf(), syntax = SweaveSyntaxRtf,
       output = tempfile(fileext = ".R"))

       

[Package rtfSweave version 0.6-0 Index]