Skip to contents

pons 0.0.0.932

New features

  • Interface between R and Microsoft Word and Excel via the Component Object Model, supplying the Office layer of the DescToolsX package suite. Windows only; requires a local Office installation and RDCOMClient.
  • toWrd() writes content of the common R classes into a running Word document, with control over font, paragraph format, style template and bullet lists.
  • toWrd() methods for data.frame, matrix, table, TOne and TMod write formatted tables (header rules, decimal-tab alignment, paragraph spacing); wrdSymbolMap() replaces -, =>, <= etc. by their typographic characters.
  • labels for the TMod, matrix and table methods of toWrd(): a named character vector or a function relabels coefficients, statistics or row names.
  • toWrd(..., bookmark = "name") encloses the output of any method in a Word bookmark; an existing bookmark is replaced in place, so re-running a script updates the report. bookmark = TRUE generates a name. The RStudio addins for text bookmarks use this mechanism.
  • font = "fix" writes text in the paragraph style “R Output” (Consolas 10 pt, line spacing 1.25, no space before/after, no spell checking), created if the document has no such style, so it can be designed in Word or a template. Name and defaults: options(pons.fixstyle = ). Tables use its font. Formerly Courier New 8 pt was set directly.
  • Plots for Word: toWrd() inserts captured plotting code (wrdPlot()), recorded base graphics (recordPlot()), ggplot and trellis objects as pictures of a given size in cm (png, emf or svg), aligned and bookmarkable (generated names start with bmp). The RStudio plot bookmark addins use this instead of the former ToWrdPlot().
  • Bookmark handling makes reports updatable in place: wrdAddBookmark(), wrdBookmark(), renameBookmark(), wrdDeleteBookmark(), bookmarkList() and wrdGoto(). replaceBookmarkText() restores the bookmark that Word discards when the underlying text is replaced.
  • xlGetRange() and xlParseRange() read an Excel selection - including disjoint multi-area selections - into a data frame, matrix, list or table, with header handling and per-column type detection.
  • xlImport() wraps the above in a Tcl/Tk dialog and either assigns the result or inserts constructive R code at the editor cursor.
  • xlView() opens data frames, matrices, tables, vectors and nested lists in Excel, with methods for lm and glm that write the coefficient table with optional confidence intervals, ANOVA and fitted values.

Documentation

  • New vignette “Reporting to Word with pons”: a short analysis of the infert data reported to Word, demonstrating all toWrd() options, plots and updatable bookmarks.

Bug fixes

  • autofit of the table methods: "window" (default, as before: content, then window width), "content" (or TRUE, the table only as wide as its content) or "none" (or FALSE). Formerly TRUE also stretched the table to the window width.

  • Default alignment: only columns holding numbers are aligned at the decimal point, text columns left; text in decimal columns had been pushed to the tab stop and wrapped. decpos = NA estimates the position like NULL.

  • Printed output (toWrd.default(), e.g. summary()) now ends with a paragraph mark; the following output ran on in the same paragraph. Text gets one with newpara = TRUE.

  • Tables written one after the other were merged by Word into one table (and setting the alignment of its columns then failed with a COM exception). A table is now followed by an empty paragraph (newpara = TRUE).

  • Numbers are formatted consistently with pharos::fm(): digits (number of decimals) and fmt (format code such as "%", or a Style) for the matrix and table methods and, applied to the numeric columns, for the data.frame method. Formerly digits meant significant digits (format()).

  • font = "fix" failed for all table methods; fonts are now resolved centrally and checked before anything is written to Word.

  • summary() of a vector (class summaryDefault, inheriting from table) was written as a table; it is written as printed text again.

  • The RStudio addin “To Word” pointed to the non-existent ToWrd(); it now calls the new xtoWrd().

  • xlParseRange() failed on multi-area selections (internal calls used the non-existent argument as = instead of output =).

  • wrdSymbolMap() was broken in non-UTF-8 locales: non-ASCII regex patterns given as argument tags were translated to <U+2264> text. The minus rule now also applies after a non-breaking space (N = -3).

  • The internal output capture failed on literal constants (“bad argument”).

Internal

  • Test suite for all COM-free parts (symbol map, table preparation, the toWrd() table methods with a mocked Word layer, xlParseRange(), type conversion, deparser, output capture).

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.