Title: Interface to Microsoft Office for the DescToolsX Ecosystem
License: GPL (≥ 2)
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/
RDCOMClient first:
install.packages("RDCOMClient", repos = "http://www.omegahat.net/R")Then:
remotes::install_github("AndriSignorell/pons")newWrd(),getWrd(),setWrd(),closeWrd(),withWrd()
toWrd()— insert content at the current selection, with methods for character vectors and arbitrary objects, and control over font, paragraph format, style template and bulletswdConst— the Word enumeration constants, so numeric values need not be looked up
wrdAddBookmark(),wrdBookmark(),wrdDeleteBookmark(),wrdRenameBookmark()wrdReplaceBookmarkText()— replace the text while preserving the bookmark, which Word would otherwise discardwrdBookmarks()— all bookmarks of the document as a data framewrdGoto()— move the selection to a bookmark or other target
newXl(),getXl(),setXl(),closeXl(),withXl(),xlKill()
xlGetRange()— raw values of the selection, including disjoint multi-area selectionsxlParseRange()— organise them into a data frame, matrix, list or table, with header handling and per-column type detectionxlImport()— the dialog-driven round trip: read, choose the structure, and either assign the object or insert constructive code at the editor cursorxlDataTransferDialog()— the Tcl/Tk front end used byxlImport()
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
cmToPts(),ptsToCm()
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)pons builds on bedrock and pharos and supplies the Office interface
used by DescToolsX and swissValet.
Parts of the code and documentation were reviewed with the help of large language models (OpenAI Codex, Anthropic Claude). Every suggestion was assessed, edited and verified by the maintainer, who remains solely responsible for the content of this package.
GPL (≥ 2)
