Learn R Programming

officer R package

Make corporate reporting with minimum hassle

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. It also supports the writing of ‘RTF’ documents and basic manipulation of Excel (‘.xlsx’) workbooks.

Ressources

The help pages are in a bookdown located at:

https://ardata-fr.github.io/officeverse/

Manuals are available at:

https://davidgohel.github.io/officer/.

Word documents

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.

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. The function docx_comments() reads comments of a Word document and organise the results into a data.frame.

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 data.frame. The function handles paragraphs, tables and images.

Extensions

Tables and package flextable

The package flextable brings a full API to produce nice tables and use them with packages officer and rmarkdown.

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.

Advance Word documents with R Markdown with package officedown

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

Installation

You can get the development version from GitHub:

devtools::install_github("davidgohel/officer")

Or the latest version on CRAN:

install.packages("officer")

Getting help

If you have questions about how to use the package, 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

Bugs are reported through GitHub issues. The issue form requires a reproducible example (a reprex) and the output of sessionInfo(); reports missing these elements are closed without further response. The more reproducible your report, the more time can go into investigating the bug rather than reconstructing it.

For usage questions (“how do I do X with officer”), please read https://ardata-fr.github.io/officeverse/ or https://davidgohel.github.io/officer/ or use Stack Overflow with the officer tag instead.

Pull requests

Before writing any code, please open an issue describing the change you have in mind and the reason for it. The proposal needs to be discussed and explicitly validated by the maintainer before work starts; pull requests for features that have not gone through this step will not be considered, no matter how well crafted. This isn’t meant to discourage contributions, only to make sure the time you invest goes into a change that will actually land.

Pull requests are accepted on a case-by-case basis: once a proposal has been agreed in an issue, the maintainer will invite you to open a PR for that specific change. Unsolicited PRs that bypass this step will be closed.

This policy keeps the package coherent: officer’s internals are shared with several downstream packages (flextable, officedown, rvg), and changes that look local often have wider implications. Aligning on the design in an issue first saves time on both sides.

When invited to open a PR, please include:

  • the new function(s) with code and roxygen tags, including runnable examples
  • documentation updates (vignette section if relevant)
  • corresponding tests under tests/testthat

Run rhub::check_for_cran() locally before submitting; CI will run the full check suite on the PR.

Copy Link

Version

Install

install.packages('officer')

Monthly Downloads

112,579

Version

0.7.6

License

MIT + file LICENSE

Maintainer

David Gohel

Last Published

July 16th, 2026

Functions in officer (0.7.6)

docx_summary

Get Word content in a data.frame
body_comment

Add comment in a 'Word' document
doc_properties

Read document properties
body_import_docx

Import an external docx in a 'Word' document
body_end_section_continuous

Add continuous section
docx_body_xml

Body xml document
docx_set_paragraph_style

Add or replace paragraph style in a Word document
docx_set_settings

Set 'Microsoft Word' Document Settings
body_replace_gg_at_bkm

Add plots at bookmark location in a 'Word' document
docx_bookmarks

List Word bookmarks
docx_body_relationship

Body xml document
docx_show_chunk

Show underlying text tag structure
docx_set_character_style

Add character style in a Word document
fp_tab

Tabulation mark properties object
docx_embed_font

Embed Fonts in a Word Document
docx_dim

'Word' page layout
fortify_location

Eval a location on the current slide
docx_comments

Get comments in a Word document as a data.frame
fp_par

Paragraph formatting properties
cursor_begin

Set cursor in a 'Word' document
fp_cell

Cell formatting properties
color_scheme

Color scheme of a PowerPoint file
fp_text

Text formatting properties
floating_external_img

Floating external image
fpar

Formatted paragraph
external_img

External image
empty_content

Empty block for 'PowerPoint'
docx_current_block_xml

xml element on which cursor is
hyperlink_ftext

Formatted chunk of text with hyperlink
from_base64

Decode Base64 Vector to Character
image_to_base64

Images to base64
layout_dedupe_ph_labels

Detect and handle duplicate placeholder labels
get_layout

Layout selection helper
get_reference_value

Get the document being used as a template
layout_properties

Slide layout properties
fp_tabs

Tabs properties object
fp_border

Border properties object
notes_location_label

Location of a named placeholder for notes
length.rpptx

Number of slides
media_extract

Extract media from a document object
list_item

Create a list item
officer

Manipulate Microsoft Word and PowerPoint Documents with 'officer'
length.rdocx

Number of blocks inside an rdocx object
ooxml_chart_uris

URIs for chart relationships in xlsx drawings
page_mar

Page margins object
ph_hyperlink

Hyperlink a placeholder
open_file

Opens a file locally
ph_location

Location for a placeholder from scratch
officer_url_encode

officer url encoder
pack_folder

compress a folder
opts_current_table

Table options in a 'knitr' context
ftext

Formatted chunk of text
ph_location_left

Location of a left body element
ph_slidelink

Slide link to a placeholder
ph_location_template

Location for a placeholder based on a template
ph_location_id

Location of a placeholder based on its id
layout_rename_ph_labels

Change ph labels in a layout
ph_location_fullsize

Location of a full size element
on_slide

Change current slide
notes_location_type

Location of a placeholder for notes
move_slide

Move a slide
layout_default

Default layout for new slides
officer-defunct

Defunct Functions in Package officer
ph_remove

Remove a shape
ph_location_right

Location of a right body element
ph_location_type

Location of a placeholder based on a type
ph_location_label

Location of a named placeholder
ph_with

Add objects on the current slide
page_size

Page size object
layout_summary

Presentation layouts summary
print.rpptx

Write a 'PowerPoint' file.
plot_layout_properties

Slide layout properties plot
prop_table

Table properties
phs_with

Fill multiple placeholders using key value syntax
plot_instr

Wrap plot instructions for png plotting in Powerpoint or Word
prop_section

Section properties
print.rdocx

Write a 'Word' File
print.rtf

Write an 'RTF' File
plot_in_png

Write a ggplot Object to PNG File
pptx_summary

PowerPoint content in a data.frame
read_pptx

Create a 'PowerPoint' document object
remove_slide

Remove slide(s)
run_autonum

Auto number
rtf_doc

Create an RTF document object
read_xlsx

Create an 'Excel' document object
resolve_location

Resolve short form location
rtf_set_paragraph_style

Add or replace a paragraph style in an RTF document
rtf_styles_info

Read paragraph styles defined on an RTF document
rtf_add

Add content into an RTF document
read_docx

Create a 'Word' document object
run_reference

Cross reference
run_pagebreak

Page break for 'Word'
run_word_field

'Word' computed field
run_footnoteref

Word footnote reference
run_tab

Tab for 'Word'
run_comment

Comment for 'Word'
run_bookmark

Bookmark for 'Word'
run_linebreak

Page break for 'Word'
run_columnbreak

Column break for 'Word'
run_footnote

Footnote for 'Word'
shape_properties_tags

pptx tags for visual and non visual properties
set_autonum_bookmark

Update bookmark of an autonumber run
sheet_add_drawing

Add a drawing to an Excel sheet
run_wordtext

Word chunk of text with a style
section_columns

Section columns
set_doc_properties

Set document properties
sanitize_images

Remove unused media from a document
sheet_remove

Remove a sheet
set_notes

Set notes for current slide
sheet_names

Sheet names of an xlsx workbook
sheet_write_data

Write data to a sheet
slide_visible<-

Get or set slide visibility
solid_fill

Solid fill DrawingML fragment
sp_line

Line properties
shortcuts

shortcuts for formatting properties
sp_lineend

Line end properties
sheet_select

Select sheet
slide_summary

Slide content in a data.frame
slide_size

Slides width and height
stop_if_not_in_slide_range

Ensure valid slide indexes
styles_info

Read 'Word' styles
to_pml

Convert officer objects to PresentationML
table_width

Preferred width for a table
table_colwidths

Column widths of a table
table_conditional_formatting

Table conditional formatting
table_stylenames

Paragraph styles for columns
table_layout

Algorithm for table layout
str_encode_to_rtf

Encode UTF8 string to RTF
to_rtf

Convert officer objects to RTF
to_html

Convert officer objects to HTML
unordered_list

Unordered list
to_wml

Convert officer objects to WordprocessingML
xlsx_drawing

Drawing manager for xlsx sheets
xlsx_styles

Style manager for xlsx workbooks
uuid_generate

generates unique identifiers
wml_link_images

transform an xml string with images references
unpack_folder

Extract files from a zip file
block_list_items

List of items for Word and PowerPoint
annotate_base

Placeholder parameters annotation
add_slide

Add a slide
as_base64

Encode Character Vector to Base64
block_gg

'ggplot' block
add_sheet

Add a sheet
block_caption

Caption block
block_list

List of blocks
as.matrix.rpptx

PowerPoint table to matrix
block_pour_docx

External Word document placeholder
body_add_caption

Add Word caption in a 'Word' document
block_table

Table block
body_add_break

Add a page break in a 'Word' document
block_toc

Table of content for 'Word'
block_section

Section for 'Word'
body_add_blocks

Add a list of blocks into a 'Word' document
body_add_docx

Add an external docx in a 'Word' document
body_add_fpar

Add fpar in a 'Word' document
body_add_list

Add a list of items into a 'Word' document
base64_to_image

Convert Data URIs to PNG Files
body_add

Add content into a Word document
body_add_table

Add table in a 'Word' document
body_add_par

Add paragraphs of text in a 'Word' document
body_add_plot

Add plot in a 'Word' document
body_add_gg

Add a 'ggplot' in a 'Word' document
body_add_img

Add an image in a 'Word' document
body_append_start_context

Fast Append context to a Word document
body_add_toc

Add table of content in a 'Word' document
body_bookmark

Add bookmark in a 'Word' document
body_add_xml

Add an xml string as document element
body_remove

Remove an element in a 'Word' document
body_end_block_section

Add any section
body_end_section_portrait

Add portrait section
body_end_section_columns

Add multi columns section
body_replace_all_text

Replace text anywhere in the document
body_end_section_landscape

Add landscape section
body_end_section_columns_landscape

Add a landscape multi columns section
body_set_default_section

Define Default Section
body_replace_text_at_bkm

Replace text at a bookmark location
change_styles

Replace styles in a 'Word' Document