ToWrdPlot {DescTools}R Documentation

Send a Plot to Word and Bookmark it

Description

Evaluate given plot code to a tiff() device and imports the created plot in the currently open MS-Word document. The imported plot is marked with a bookmark that can later be used for a potential update (provided the bookmark name has been stored).

Usage

ToWrdPlot(plotcode, width = NULL, height = NULL, scale = 100,
          pointsize = 12, res = 300, crop = 0, title = NULL,  
          wrd = DescToolsOptions("lastWord"), 
          bookmark = gettextf("bmp%s", round(runif(1, min = 0.1) * 1e+09)))

Arguments

plotcode

code chunk needed for producing the plot

bookmark

character, the name of the bookmark

width

the width in cm of the plot in the Word document (default 15)

height

the height in cm of the plot in the Word document (default 9.3)

scale

the scale of the plot (default 100)

pointsize

the default pointsize of plotted text, interpreted as big points (1/72 inch) at res ppi. (default is 12)

res

the resolution for the graphic (default 300)

crop

a vector of 4 elements, the crop factor for all 4 sides of a picture in cm (default all 0)

title

character, the title of the plot to be inserted in the word document

wrd

the pointer to a word instance. Can be a new one, created by GetNewWrd() or an existing one, created by GetCurrWrd(). Default is the last created pointer stored in DescToolsOptions("lastWord").

Details

An old and persistent problem that has existed for a long time is that as results once were loaded into a Word document the connection broke so that no update was possible. It was only recently that I realized that bookmarks in Word could be a solution for this. The present function evaluates some given plot code chunk using a tiff device and imports the created plot in a word document. The imported plot is given a bookmark, that can be used afterwards for changing or updating the plot.

This function is designed for use with the DescToolsAddIns functions ToWrdPlotWithBookmark() and ToWrdWithBookmark() allowing to assign keyboard shortcuts. The two functions will also insert the newly defined bookmark in the source file in a format, which can be interpreted by the function UpdateBookmark().

Value

a list

plot_hwnd

a windows handle to the inserted plot

bookmark

a windows handle to the bookmark

Author(s)

Andri Signorell <andri@signorell.net>

See Also

ToWrdB, WrdInsertBookmark

Examples

## Not run: 
# we can't get this through the CRAN test - run it with copy/paste to console

wrd <- GetNewWrd()
bm <- ToWrdB("This is text to be possibly replaced later.")

# get the automatically created name of the bookmark
bm$name()

WrdGoto(bm$name())
UpdateBookmark(...)

## End(Not run)

[Package DescTools version 0.99.54 Index]