Learn R Programming

DescToolsAddIns (version 1.8)

Operating MS Word: Operating MS Word

Description

Controlling MS Word with RStudio has many convenient advantages. We can quickly create some reports on the fly and also use bookmarks to create dynamically updatable report chunks such as tables or graphics. Here we implement a set of functions to handle bookmarks in MS Word.

Usage

ToWrd()
ToWrdWithBookmark()

CreateBookmark() SelectBookmark() UpdateBookmark() DeleteBookmark()

Arguments

Details

ToWrd() simply sends the selected object to the current Word instance. The Word summary logic is generic and depends on the object. There are summaries for characters, tables, models etc.. The inserted text is however not later updateable; as soon as it is inserted in the Word document the connection is lost.

ToWrdWithBookmark() inserts the object in the Word document and defines a bookmark that covers the whole inserted object (including tables or graphics). Then the selected command chunk in the Rstudio source pane is enclosed in brackets and the name of the new defined bookmark is inserted as meta tag. If the R-code is later changed, the output in Word can simply be refreshed by selecting the code chunk in RStudio (including the meta tag) and click on UpdateBookmark().

CreateBookmark() would create a bookmark on the currently selected text in Word and use the currently selected text in RStudio as name. SelectBookmark(), DeleteBookmark() behave analogously.