Skip to content
AndriSignorellPublic

About

Interface to MS-Office for the DescToolsX ecosystem

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

22 Commits

Folders and files

Repository files navigation

📦 pons pons logo

License: GPL (>= 2) R-CMD-check

Interface to Microsoft Word and Excel

🧩 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. pons requires a local installation of Microsoft Office and depends on RDCOMClient, 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")

For R >= 4.6, the patched version may be needed:

remotes::install_github("AndriSignorell/RDCOMClient@r46-unicode")

Then:

install.packages("pons")

📚 Core Features

🔹 Word Sessions

  • newWrd(), getWrd(), setWrd(), closeWrd(), withWrd(), wrdKill()
  • wrdOpen(), wrdSave(), wrdSaveAs() — open a document, save it, save it under a new name or as PDF

🔹 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
  • wrdHeading(), wrdPageBreak() — headings in the built-in heading styles, page and section breaks
  • wrdFont(), wrdPara(), wrdStyle() — get or set font, paragraph format and style of the selection
  • 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

🔹 Excel Sessions

  • newXl(), getXl(), setXl(), closeXl(), withXl(), xlKill()
  • xlOpen(), xlSave(), xlSaveAs() — open a workbook, save it, save it under a new name or as PDF

🔹 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 by xlImport()
  • xlNamedRanges() — the named ranges of the workbook, to be read with xlGetRange()
  • xlDateToDate(), xlDateToPOSIXct() — convert Excel serial dates, for both the 1900 and the 1904 date system

🔹 Writing to Excel

  • xlView() — open a data frame, matrix, table, vector or nested list in Excel, with methods for lm and glm that write the coefficient table, optionally with confidence intervals, ANOVA and fitted values

🔹 Utilities

  • a1ToR1C1(), r1C1ToA1() — convert cell references between A1 and R1C1 notation (also German Z1S1 and French L1C1)
  • cmToPts(), ptsToCm() — centimetres and points

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

🙏 Acknowledgements

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.

📜 License

GPL (≥ 2)

About

Interface to MS-Office for the DescToolsX ecosystem

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages