Manipulation of Microsoft Word and PowerPoint Documents

Access and manipulate 'Microsoft Word' and 'Microsoft PowerPoint' documents from R. The package focuses on tabular and graphical reporting from R; it also provides two functions that let users get document content into data objects. A set of functions lets add and remove images, tables and paragraphs of text in new or existing documents. The package does not require any installation of Microsoft products to be able to write Microsoft files.

The officer package lets R users manipulate Word (.docx) and PowerPoint (*.pptx) documents. In short, one can add images, tables and text into documents from R. An initial document can be provided; contents, styles and properties of the original document will then be available.

This package is close to ReporteRs as it produces Word and PowerPoint files but it is faster, does not require rJava and is easier to maintain.

Travis-CI BuildStatus Buildstatus version cranlogs codecov Active

The read_docx() function will read an initial Word document (an empty one by default) and lets you modify its content later.

The package provides functions to add R outputs into a Word document:

  • images: produce your plot in png or emf files and add them into the document, as a whole paragraph or inside a paragraph.
  • tables: add data.frames as tables, format is defined by the associated Word table style.
  • text: add text as paragraphs or inside an existing paragraph, format is defined by the associated Word paragraph and text styles.
  • field codes: add Word field codes inside paragraphs. Field codes is an old feature of MS Word to create calculated elements such as tables of contents, automatic numbering and hyperlinks.

In a Word document, one can use cursor functions to reach the beginning or end of a document, or a particular paragraph containing a given text. This cursor concept has been implemented to make the post processing of files easier.

File generation is performed with the print function.

import Word document in a data.frame

The function docx_summary() reads and imports content of a Word document into a data.frame. The function handles paragraphs, tables and section breaks.

PowerPoint documents

The function read_pptx() will read an initial PowerPoint document (an empty one by default) and let you modify its content later.

The package provides functions to add R outputs into existing or new PowerPoint slides:

  • images: produce your plot in png or emf files and add them in a slide.
  • tables: add data.frames as tables, format is defined by the associated PowerPoint table style.
  • text: add text as paragraphs or inside an existing paragraph, format is defined in the corresponding layout of the slide.

In a PowerPoint document, one can set a slide as selected and reach a particular shape (and remove it or add text).

File generation is performed with the print() function.

import PowerPoint document in a data.frame

The pptx_summary() function reads and imports content of a PowerPoint document into a tibble object. The function handles paragraphs, tables and images.


Tables and package flextable

The package flextable brings a full API to produce nice tables and use them with officer. Tables can be written in PowerPoint documents and Word documents. An option is available to render flextables in rmarkdown (HTML and Word outputs).

Vector graphics with package rvg

The package rvg brings an API to produce nice vector graphics that can be embedded in PowerPoint documents or Excel workbooks with officer.

Native office charts with package mschart

The package mschart combined with officer can produce native office charts in PowerPoint and Word documents.


You can get the development version from GitHub:


Or the latest version on CRAN:



Online documentation

The help pages are located at

Getting help

This project is developed and maintained on my own time. In order to help me to maintain the package, do not send me private emails if you only have questions about how to use the package. Instead, visit Stack Overflow’s officer tag and post your question there. I usually read them and answer when possible.

Contributing to the package

Code of Conduct

Anyone getting involved in this package agrees to our Code of Conduct.

Bug reports

When you file a bug report, please spend some time making it easy for me to follow and reproduce. The more time you spend on making the bug report coherent, the more time I can dedicate to investigate the bug as opposed to the bug report.

Contributing to the package development

A great way to start is to contribute an example or improve the documentation.

If you want to submit a Pull Request to integrate functions of yours, please provide:

  • the new function(s) with code and roxygen tags (with examples)
  • a new section in the appropriate vignette that describes how to use the new function
  • add corresponding tests in directory tests/testthat.

By using rhub (run rhub::check_for_cran()), you will see if everything is ok. When submitted, the PR will be evaluated automatically on travis and appveyor and you will be able to see if something broke.


officer 0.3.4


  • fix external_img size issue with method ph_with.

officer 0.3.3


  • new generic function ph_with() and function ph_location*() to ease insertion of elements.
  • new function slide_size() provide size of slides.


  • fix issue with fonts when east asian characters are used in Word.

officer 0.3.2


  • new function change_styles() to change paragraph styles in a Word document.
  • new function move_slide(): move a slide in a presentation.
  • fix body_add_docx examples


  • fix issue with text underlined and justified paragraphs in Word.
  • skip errored test on macOS that can be read on CRAN check page.
  • all examples are now generated in tempdir().

officer 0.3.1


  • fix function body_add_fpar() when argument style was used.
  • slide_summary was using a bad xpath query.
  • fixed character encoding issue for filename whith windows OS

officer 0.3.0


  • function cursor_bookmark now let set the cursor in a text box thanks to Noam Ross. cursor_forward and cursor_backward can now fail if cursor is on a textbox but an error message will explain it to the user.
  • Word documents support now footnotes.
  • Word section functions have been refactored.
  • New functions for replacement in headers and footers in Word documents. See functions headers_replace* and footers_replace*
  • PowerPoint processing optimisation when generating more than few slides.


  • fix an issue with layout_properties when master layout is empty.

officer 0.2.2


  • rdocx objects support external docx insertion
  • Word margins can be modified now (thanks to Jonathan Cooper)
  • New function ph_fpars_at() to add several formated paragraphs in a new shape.
  • Function annotate_base will generate a slide to identify the placeholder indexes, master names and indexes.


  • fix issue with duplicated lines in layout_properties(#103)
  • new argument par_default in ph_add_fpar so fpar par. properties can be kept as is.
  • fix issue with images when duplicated basename()s

officer 0.2.1


  • fix issue #97 with function pptx_summary()

officer 0.2.0


  • new function body_replace_all_text() to replace any text in a Word document
  • new functions for xlsx files (experimental).
  • new functions ph_with_gg() and ph_with_gg_at() to make easier production of ggplot objects in PowerPoint
  • new functions ph_with_ul() to make easier production of unordered lists of text in PowerPoint


  • an error is raised when adding an image with blank(s) in its basename (i.e. /home/user/bla bla.png).

officer 0.1.8


  • decrease execution time necessary to add elements into big slide deck
  • fix encoding issue in function "*_add_table"
  • fix an issue with complex slide layouts (there is still an issue left but don't know how to manage it for now)


  • Functions slide_summary and layout_properties now return inches.

officer 0.1.7


  • new function body_replace_at to replace text inside bookmark
  • argument header for body_add_table and ph_with_table.
  • layout_properties now returns placeholder id when available.


  • an error is now occurring when an incorrect index is used with ph_with_* functions.

officer 0.1.6


  • function ph_empty_at can now make new shapes inherit properties from template


  • drop gdtools dependency

officer 0.1.5


  • new function body_default_section
  • fp_border supports width in double precision


  • characters <, > and & are now html encoded
  • on_slide index is now the correct slide number id.


  • drop dplyr deprecated verbs from code
  • rename break_column to break_column_before.

officer 0.1.4


  • body_end_section is supposed to only work with cursor on a paragraph, an error is raised now if ending a section on something else than a paragraph.


  • read_pptx run faster than in previous version thanks to some code refactoring

officer 0.1.3

new feature

  • new function media_extract to extract a media file from a document object. This function can be used to access images stored in a PowerPoint file.


  • drop magick dependence

officer 0.1.2

new features

  • new functions docx_summary and pptx_summary to import content of an Office document into a tidy data.frame.
  • new function docx_dim() is returning current page dimensions.
  • new functions set_doc_properties and doc_properties to let you modify/access metadata of Word and PowerPoint documents.
  • cursor can now reach paragraphs with a bookmark (functions body_bookmark and cursor_bookmark).
  • Content can be inserted at any arbitrary location in PowerPoint (functions ph_empty_at, ph_with_img_at and ph_with_table_at).


  • cast all columns of data.frame as character when using ph_with_table and body_add_table
  • fix pptx when more than 9 slides

officer 0.1.1


  • argument style of functions body_add* and slip_in* now will use docx default style if not specified
  • new function body_add_gg to add ggplots to Word documents
  • new function test_zip for diagnostic purpose

API changes

  • classes docx and pptx have been renamed rdocx and pptx to avoid conflict with package ReporteRs.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.4.0 by David Gohel, 2 months ago,

Report a bug at

Browse source code at

Authors: David Gohel [aut, cre] , Frank Hangler [ctb] (function body_replace_all_text) , Liz Sander [ctb] (several documentation fixes) , Anton Victorson [ctb] (fixes xml structures) , Jon Calder [ctb] (update vignettes) , John Harrold [ctb] (function annotate_base) , John Muschelli [ctb] (google doc compatibility)

Documentation:   PDF Manual  

Task views: Reproducible Research

GPL-3 license

Imports R6, grDevices, stats, graphics, utils, zip, uuid, xml2

Suggests testthat, devEMF, ggplot2, rmarkdown, base64enc, knitr, rsvg

Imported by DescrTab2, EpiReport, GWSDAT, MCPModPack, RtutoR, SWMPrExtension, WordR, augmentedRCBD, compareGroups, concurve, crosstable, demoGraphic, documenter, eoffice, flextable, inTextSummaryTable, interactionR, jsmodule, microplot, mschart, officedown, onbrand, presenter, processR, r2pptx, repmod, rrtable, rvg, thinkr, ztable.

Suggested by Mediana, basictabler, bfw, esquisse, gtsummary, huxtable, modelsummary, nlmixr, rtables, statgenGWAS, strand, ubiquity.

See at CRAN