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.
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:
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.
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 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:
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.
The pptx_summary()
function reads and imports content of a PowerPoint
document into a tibble object. The function handles paragraphs, tables
and images.
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).
rvg
The package rvg brings an API to
produce nice vector graphics that can be embedded in PowerPoint
documents or Excel workbooks with officer
.
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:
devtools::install_github("davidgohel/officer")
Or the latest version on CRAN:
install.packages("officer")
The help pages are located at https://davidgohel.github.io/officer/.
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.
Anyone getting involved in this package agrees to our Code of Conduct.
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.
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:
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.
external_img
size issue with method ph_with
.ph_with()
and function ph_location*()
to ease insertion
of elements.slide_size()
provide size of slides.change_styles()
to change paragraph styles in
a Word document.move_slide()
: move a slide in a presentation.tempdir()
.body_add_fpar()
when argument style
was used.slide_summary
was using a bad xpath query.headers_replace*
and footers_replace*
layout_properties
when master layout is empty.ph_fpars_at()
to add several formated paragraphs
in a new shape.basename()
spptx_summary()
body_replace_all_text()
to replace
any text in a Word documentph_with_gg()
and ph_with_gg_at()
to make easier
production of ggplot objects in PowerPointph_with_ul()
to make easier
production of unordered lists of text in PowerPointbody_replace_at
to replace text inside bookmarkbody_add_table
and ph_with_table
.layout_properties
now returns placeholder id when available.ph_empty_at
can now make new shapes inherit
properties from templatebody_default_section
break_column
to break_column_before
.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.docx_summary
and pptx_summary
to import content of an Office document into a tidy data.frame.docx_dim()
is returning current page dimensions.set_doc_properties
and doc_properties
to let you modify/access metadata of Word and PowerPoint documents.body_bookmark
and cursor_bookmark
).ph_empty_at
, ph_with_img_at
and ph_with_table_at
).style
of functions body_add*
and slip_in*
now will use docx default style if not specifieddocx
and pptx
have been renamed rdocx
and pptx
to avoid conflict with package ReporteRs.