Learn R Programming

⚠️There's a newer version (0.6.8) of this package.Take me there.

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.

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.

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

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.

Copy Link

Version

Install

install.packages('officer')

Monthly Downloads

92,776

Version

0.4.1

License

GPL-3

Maintainer

David Gohel

Last Published

November 14th, 2021

Functions in officer (0.4.1)

block_toc

Table of content
block_list

List of blocks
add_sheet

add a sheet
block_caption

Caption block
add_slide

add a slide
block_pour_docx

Pour external Word document in the current document
block_section

New Word section
annotate_base

PowerPoint placeholder parameters annotation
body_add

Add content into a Word document
block_table

Table block
body_add_caption

add Word caption
body_end_section_portrait

add portrait section
body_add_img

add image
body_add_plot

add plot
docx_bookmarks

List Word bookmarks
body_add_blocks

add a list of blocks into a document
body_end_section_landscape

add landscape section
body_add_break

add page break
body_end_section_continuous

add continuous section
docx_body_xml

body xml document
body_add_table

add table
body_remove

remove an element
color_scheme

color scheme
body_add_par

add paragraph of text
cursor_begin

set cursor in an rdocx object
fp_par

Paragraph formatting properties
fp_cell

Cell formatting properties
body_add_fpar

add fpar
body_add_toc

add table of content
body_add_xml

add an xml string as document element
change_styles

Replace Styles in a Word Document
body_set_default_section

Define Default Section
empty_content

create empty blocks
length.rpptx

number of slides
docx_dim

Word page layout
doc_properties

read document properties
body_add_docx

insert an external docx
body_end_section_columns

add multi columns section
body_add_gg

add ggplot
docx_body_relationship

body xml document
ph_add_par

append paragraph
media_extract

Extract media from a document object
ph_add_fpar

append fpar
prop_section

section properties
layout_summary

presentation layouts summary
external_img

external image
body_end_section_columns_landscape

add multi columns section within landscape orientation
ftext

formatted chunk of text
get_reference_value

Get the document being used as a template
opts_current_table

Get table options in a 'knitr' context
ph_location_template

create a location for a placeholder based on a template
ph_location_right

location of a right body element
docx_show_chunk

Show underlying text tag structure
pack_folder

compress a folder
prop_table

Table properties
length.rdocx

number of blocks inside an rdocx object
remove_slide

remove a slide
read_xlsx

open a connexion to an 'Excel' file
run_word_field

seqfield
sanitize_images

remove unused media from a document
plot_layout_properties

Plot slide layout properties
plot_instr

Wrap plot instructions for png plotting in Powerpoint or Word
docx_reference_img

add images into an rdocx object
hyperlink_ftext

formatted chunk of text with hyperlink
docx_summary

get Word content in a data.frame
layout_properties

slide layout properties
unordered_list

Unordered list
page_size

page size object
page_mar

page margins object
move_slide

move a slide
officer-defunct

Defunct Functions in Package officer
slip_in_img

append an image
slip_in_footnote

append a footnote
body_bookmark

add bookmark
ph_remove

remove a shape
ph_location_type

location of a placeholder based on a type
ph_location_left

location of a left body element
pptx_summary

get PowerPoint content in a data.frame
ph_location_label

location of a named placeholder
body_end_block_section

add any section
body_replace_all_text

Replace text anywhere in the document, or at a cursor
unpack_folder

Extract files from a zip file
body_replace_text_at_bkm

replace text at a bookmark location
fp_text

Text formatting properties
fp_border

border properties object
fortify_location

eval a location on the current slide
fpar

Concatenate formatted text as a paragraph
run_bookmark

bookmark for Word
set_autonum_bookmark

update bookmark of an autonumber run
run_autonum

auto number
section_columns

section columns
to_pml

Convert officer objects to PresentationML
print.rpptx

write a 'PowerPoint' file.
to_wml

Convert officer objects to WordprocessingML
ph_location_fullsize

location of a full size element
ph_with

add objects into a new shape on the current slide
sheet_select

select sheet
run_footnote

Word footnote
ph_slidelink

slide link to a placeholder
run_columnbreak

column break
set_doc_properties

set document properties
ph_location

create a location for a placeholder
table_layout

Algorithm for table layout
table_stylenames

Paragraph styles for columns
slip_in_xml

add a wml string into a Word document
ph_hyperlink

hyperlink a placeholder
read_pptx

open a connexion to a 'PowerPoint' file
on_slide

change current slide
officer

officer: Manipulate Microsoft Word and PowerPoint Documents
ph_add_text

append text
read_docx

Create a 'Word' document object
run_pagebreak

page break for Word
shortcuts

shortcuts for formatting properties
run_reference

reference
slide_size

slides width and height
slip_in_seqfield

append seq field
run_footnoteref

Word footnote reference
slip_in_text

append text
slide_summary

get PowerPoint slide content in a data.frame
table_colwidths

Column widths of a table
wml_link_images

transform an xml string with images references
slip_in_column_break

add a column break
table_conditional_formatting

Table conditional formatting
run_linebreak

page break for Word
to_html

Convert officer objects to HTML
styles_info

read Word styles
table_width

Preferred width for a table