Title: Interface to Microsoft Office for the DescToolsX Ecosystem
License: GPL (โฅ 2)
๐งฉ Overview
pons is the bridge between R and Microsoft Office. It writes R results into a running Word document and reads Excel selections back into R, both through the Component Object Model.
The bookmark functions are what make reporting repeatable: place a bookmark once in a Word template, and wrdReplaceBookmarkText() refills it on every run. A report is then updated in place rather than rebuilt from scratch, and the layout stays where the author put it.
Windows only.
ponsrequires a local installation of Microsoft Office and depends onRDCOMClient, which is distributed through the Omegahat repository rather than CRAN.
๐ Documentation: https://andrisignorell.github.io/pons/
โ๏ธ Installation
RDCOMClient first:
install.packages("RDCOMClient", repos = "http://www.omegahat.net/R")Then:
remotes::install_github("AndriSignorell/pons")๐ Core Features
๐น Writing to Word
-
toWrd()โ insert content at the current selection, with methods for character vectors and arbitrary objects, and control over font, paragraph format, style template and bullets -
wdConstโ the Word enumeration constants, so numeric values need not be looked up
๐น Bookmarks
-
wrdAddBookmark(),wrdBookmark(),wrdDeleteBookmark(),wrdRenameBookmark() -
wrdReplaceBookmarkText()โ replace the text while preserving the bookmark, which Word would otherwise discard -
wrdBookmarks()โ all bookmarks of the document as a data frame -
wrdGoto()โ move the selection to a bookmark or other target
๐น Reading from Excel
-
xlGetRange()โ raw values of the selection, including disjoint multi-area selections -
xlParseRange()โ organise them into a data frame, matrix, list or table, with header handling and per-column type detection -
xlImport()โ the dialog-driven round trip: read, choose the structure, and either assign the object or insert constructive code at the editor cursor -
xlDataTransferDialog()โ the Tcl/Tk front end used byxlImport()
๐น Writing to Excel
-
xlView()โ open a data frame, matrix, table, vector or nested list in Excel, with methods forlmandglmthat write the coefficient table, optionally with confidence intervals, ANOVA and fitted values
๐งช Example
library(pons)
# a new document and some content
wrd <- newWrd()
toWrd("Results", style = "heading 1")
toWrd(summary(lm(mpg ~ wt, mtcars)))
# refill a bookmark in a template
wrdReplaceBookmarkText("n_patients", "1'284")
# read the current Excel selection
xl <- getXl()
d <- xlParseRange(xlGetRange(xl), output = "data.frame", header = TRUE)
# send a model to Excel
xlView(glm(am ~ wt, mtcars, family = binomial),
conf.level = 0.95, exponentiate = TRUE)๐งฑ The Suite
pons builds on bedrock and pharos and supplies the Office interface used by DescToolsX and swissValet.
