Learn R Programming

DescTools (version 0.99.30)

ToWrdPlot: Send a Plot to Word and Bookmark it

Description

Evaluate given plot code and sends the resulting plot to a MS-Word document and adds a bookmark to it. This has the advantage, that the plot in the Word document can be updated later, provided the bookmark name has been stored.

Usage

ToWrdPlot(plotcode, width = NULL, height = NULL, scale = 100,
          res = 300, crop = c(0, 0, 0, 0), 
          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)

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)

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").

Value

a list

plot_hwnd

a windows handle to the inserted plot

bookmark

a windows handle to the bookmark

%% ...

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 give 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.

See Also

ToWrdB, WrdInsertBookmark

Examples

Run this code
# 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(...)
# }

Run the code above in your browser using DataLab