Chapter 1 Introduction

This book deals with reporting from R with the packages ‘officer’, ‘officedown’, ‘flextable’, ‘rvg’ and ‘mschart’.

These packages are available from CRAN or from github in their development version.

These packages have been developed to facilitate the production of Word documents and PowerPoint presentations from and with R. It was written specifically to offer a competitive solution to SAS ODS for tabular and graphical reporting.

1.1 The officeverse

1.1.1 officer

‘officer’ is written to generate Word or PowerPoint documents, that’s all!

‘rmarkdown’ is a Literate Programming framework and tabular and graphical reporting is quite different from literate programming. If your goal is to produce content that is essentially composed of tables, graphs, tables of contents, ‘officer’ may be the right solution. But if your goal is to write a lot of text in your document, it is highly recommended to prefer ‘officedown’ to ‘officer’. ‘officedown’ was written to take advantage of the benefits of ‘rmarkdown’ and ‘officer’.

The ‘officer’ package is ideal in cases such as:

  • producing reports from a shiny application
  • clinical reporting
  • the automation of reporting in compliance with the official corporate templates

1.1.2 officedown

The package facilitates the formatting of Microsoft Word documents produced by R Markdown documents.

The package brings some features of the “officer” package in R Markdown documents such as :

  • the ability to insert a paragraph with complex formatting,
  • the structuring of content into sections,
  • formatting of tables and lists according to a Word template,
  • the use of Word’s calculated fields for references and captions.

It also excels at creating PowerPoint with R Markdown. It essentially allows to add editable vector graphics and to position several elements freely in a slide.

1.1.3 flextable

The flextable package provides a framework for easily creating tables for reporting and publications. Functions are provided to let users create tables, modify and format their content.

Tables can be embedded within R Markdown documents (with support for HTML, Word, PDF and PowerPoint documents), Microsoft Word or PowerPoint documents with package officer also PDF documents with package pagedown.

Tables can also be rendered as R plots or graphic files (png, pdf and jpeg).

1.1.4 mschart

The package mschart combined with ‘officer’ can produce native office charts in PowerPoint and Word documents. Unlike rvg, data are embed in the document and linked to the chart. Chart can be edited, annotated and resized, if data are updated in the document, the chart will be updated.

1.1.5 rvg

The package rvg brings an API to produce nice vector graphics that can be embedded in PowerPoint documents or Excel workbooks with ‘officer’. The graphical elements can be modified (for example, change color, size, add text).

Users of the package appreciate its capability to generate high-quality vector graphics that can be seamlessly integrated into PowerPoint presentations or Excel workbooks using the ‘officer’ package. One key aspect that sets ‘rvg’ apart is its flexibility in allowing users to modify various details of the generated graphs even after their initial creation: users have the freedom to make adjustments to graphical elements, such as changing colors, altering sizes, or adding text annotations.

1.2 Other resources


Blog posts

Len Kiefer wrote two very good blog posts about ‘officer’, he is providing nice examples with the corresponding R code:

Eric Nanz gave a short presentation about using ‘officer’ in the Advanced R Markdown workshop held at the 2019 RStudio conference: