Learn R Programming

ReporteRs R package

Overview

ReporteRs is an R package for creating Microsoft Word and Powerpoint documents. It does not require any Microsoft component to be used. It runs on Windows, Linux, Unix and Mac OS systems. It is designed to automate reporting generation from R.

Important note

ReporteRs will be maintained but will not evolve anymore. It has been rewritten with no java dependency:

  • The new package is officer.
  • FlexTable objects are now implemented in package flextable.
  • Vector graphics are now implemented in package rvg
  • Native Microsoft charts can be produced with package mschart

Introduction

You can use the package as a tool for fast reporting and as a tool for reporting automation.

There are several features to let you format and present R outputs, for example:

  • Editable Vector Graphics: let your readers modify and annotate plots.
  • Tables: FlexTable objects let you format any complex table.
  • Text output: format texts and paragraphs.
  • Reuse of corporate template document (*.docx and *.pptx).

Produce a document in few lines of codes

There are default templates and default values, it enables easy generation of R outputs in few lines of codes.

Below a short R script:

require( ggplot2 )
doc = docx( title = 'My document' )

doc = addTitle( doc , 'First 5 lines of iris', level = 1)
doc = addFlexTable( doc , vanilla.table(iris[1:5, ]) )

doc = addTitle( doc , 'ggplot2 example', level = 1)
myggplot = qplot(Sepal.Length, Petal.Length, data = iris, color = Species, size = Petal.Width )
doc = addPlot( doc = doc , fun = print, x = myggplot )

doc = addTitle( doc , 'Text example', level = 1)
doc = addParagraph( doc, 'My tailor is rich.', stylename = 'Normal' )

writeDoc( doc, "demo.docx" )

Reporting automation

It lets you also create corporate documents, creation of complex tables, pretty graphical rendering with a set of R functions.

To automate document generation only R code is necessary.

With Word and PowerPoint document, you can add contents from R but also replace contents. By default, content is added at the end of the specified template document. When generating Word document, bookmarks can be used to define locations of replacements in the document. When generating PowerPoint document, slide indexes can be used to define locations of slides to replace in the presentation.

Installation

ReporteRs needs rJava with a java version >= 1.6 ; make sure you have an installed JRE.

system("java -version") should return java version ‘1.6.0’ or greater.

Test your rJava installation with the following code, you should get your java version in a string:

require(rJava)
.jinit()
#> [1] 0
.jcall('java.lang.System','S','getProperty','java.version')
#> [1] "1.8.0_31"

Get CRAN version

install.packages('ReporteRs')

From Github

devtools::install_github('davidgohel/ReporteRsjars')
devtools::install_github('davidgohel/ReporteRs')

Ressources

Online documentation

The help pages are located at https://davidgohel.github.io/ReporteRs/.

Getting help

This project is developped 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 Stackoverflow, ReporteRs has its own tag Stackoverflow link! I usually read them and answer when possible.

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.

Copy Link

Version

Monthly Downloads

177

Version

0.8.10

License

GPL-3

Maintainer

Last Published

March 28th, 2018

Functions in ReporteRs (0.8.10)

[<-.FlexRow

modify FlexRow content
FlexCell

Cell object for FlexTable
[<-.FlexTable

alter FlexTable content and format
CodeBlock

Code Block Object
FlexTable

FlexTable creation
add.pot

add a paraggraph to an existing set of paragraphs of text
Footnote

Create a Footnote
ReporteRs-package

ReporteRs: a package to create document from R
addFlexTable

Insert a FlexTable into a document object
FlexRow

Row object for FlexTable
addFooterRow

add footer in a FlexTable
RScript

RScript object
addHeaderRow

add header in a FlexTable
addColumnBreak

Add a column break into a section
addPageBreak

Add a page break into a document object
addDocument

Add an external document into a document object
addPlot

Add a plot into a document object
addDate

Insert a date
addParagraph

Add a paragraph into a document object
addCodeBlock

Add code block into a document object
addParagraph.Footnote

Insert a paragraph into a Footnote object
addSlide

Add a slide into a document object
addFooter

Insert a footer into a document object
addSubtitle

Add a subtitle shape into a document object
as.FlexTable

R tables as FlexTables
addPageNumber.pptx

Insert a page number shape into a document pptx object
addImage

Add an external image into a document object
cellProperties

Cell formatting properties
is.color

color checking
addPageNumber

Insert a page number into a document object
addFooter.pptx

Insert a footer shape into a document pptx object
light.table

light FlexTable shortcut
addRScript

Add R script into a document object
as.html

get HTML code
colorProperties

color properties object
addSection

Add a section into a document object
chprop.FlexTable

format FlexTable
as.html.pot

get HTML code from a pot
chprop

Change a formatting properties object
as.FlexTable.sessionInfo

get FlexTable from a sessionInfo object
addTOC

Add a table of contents into a document object
deleteBookmark

delete a bookmark into a docx object
borderProperties

border properties object
slide.layouts

Get layout names of a document object
addTitle

Add a title
slide.layouts.pptx

Get layout names of a pptx document
docx

Create Microsoft Word document object representation
as.html.FlexTable

get HTML code from a FlexTable
print.Footnote

print a Footnote
textNormal

shortcuts for formatting properties
list_bookmarks

List Bookmarks from a Word Document
knit_print.FlexTable

FlexTable custom printing function for knitr
setRowsColors

applies background colors to rows of a FlexTable
renderFlexTable

FlexTable output for shiny
parProperties

Paragraph formatting properties
setZebraStyle

FlexTable rows zebra striping
list.settings

format ordered and unordered lists
+.pot

pot concatenation
pptx

Create Microsoft PowerPoint document object representation
setFlexTableWidths

set columns widths of a FlexTable
deleteBookmarkNextContent

delete first content after a bookmark into a docx object
print.FlexTable

Print FlexTables
setFlexTableBackgroundColors

applies background colors to cells of a FlexTable
pot

Piece of Text (formated text)
pot_img

Image to be concatenate with pot object
office_web_viewer

Office Web Viewer
setFlexTableBorders

change grid lines of a FlexTable
styles

Get styles names of a document object
map_title

map titles styles
setColumnsColors

applies background colors to columns of a FlexTable
text_extract

Simple Text Extraction From a Word Document
spanFlexTableColumns

Span columns within rows
set_of_paragraphs

Set of paragraphs of text
toc.options

Set TOC options
spanFlexTableRows

Span rows within columns
textProperties

Text formatting properties
vanilla.table

vanilla FlexTable shortcut
writeDoc

Write a document object