Learn R Programming

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

officer R package

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.

This package is close to ReporteRs as it produces Word and PowerPoint files but it is faster, do not require rJava (but xml2) and has less functions that will make it easier to maintain.

Word documents

Function read_docx will read an initial Word document (an empty one by default) and let 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 content, automatic numbering and hyperlinks.

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

The file generation is performed with function print.

import Word document in a data.frame

Function docx_summary read and import content of a Word document into a tibble object. The function handles paragraphs, tables and section breaks.

PowerPoint documents

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).

The file generation is performed with function print.

import PowerPoint document in a data.frame

Function pptx_summary read and import 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.

Installation

You can get the development version from GitHub:

devtools::install_github("davidgohel/officer")

Or the latest version on CRAN:

install.packages("officer")

Copy Link

Version

Install

install.packages('officer')

Monthly Downloads

92,776

Version

0.1.3

License

GPL-3

Maintainer

David Gohel

Last Published

May 1st, 2017

Functions in officer (0.1.3)

body_add_xml

add an xml string as document element
body_bookmark

add bookmark
body_add_table

add table
body_add_toc

add table of content
add_slide

add a slide
body_add_break

add page break
body_add_img

add image
body_add_par

add paragraph of text
body_add_fpar

add fpar
body_add_gg

add ggplot
body_end_section

add section
body_remove

remove an element
media_extract

Extract media from a document object
on_slide

change current slide
fp_sign

object unique signature
fp_text

Text formatting properties
ph_hyperlink

hyperlink a placeholder
ph_remove

remove shape
doc_properties

read document properties
docx_dim

Word page layout
ph_slidelink

slide link to a placeholder
ph_with_img

add image
slide_summary

get PowerPoint slide content in a tidy format
slip_in_img

append an image
unpack_folder

Extract files from a zip file
wml_link_images

transform an xml string with images references
color_scheme

color scheme
cursor_begin

set cursor in an rdocx object
fpar

concatenate formatted text
read_pptx

open a connexion to a 'PowerPoint' file
remove_slide

remove a slide
docx_reference_img

add images into an rdocx object
docx_summary

get Word content in a tidy format
fp_cell

Cell formatting properties
fp_par

Paragraph formatting properties
pack_folder

compress a folder
ph_add_fpar

append fpar
shortcuts

shortcuts for formatting properties
ftext

formatted text
ph_empty

add a new empty shape
ph_from_xml

add an xml string as new shape
ph_add_par

append paragraph
ph_add_text

append text
pptx_summary

get PowerPoint content in a tidy format
read_docx

open a connexion to a 'Word' file
set_doc_properties

set document properties
slip_in_xml

add a wml string into a Word document
styles_info

read Word styles
external_img

external image
fp_border

border properties object
layout_properties

slide layout properties
layout_summary

presentation layouts summary
ph_with_table

add table
ph_with_text

add text into a new shape
slip_in_seqfield

append seq field
slip_in_text

append text