## Installation

Install ReporteRs from cran with the following command:


install.packages("ReporteRs")

Install developement version of ReporteRs from Github with the following command:

devtools::install_github("davidgohel/ReporteRs")

### Dependancies

ReporteRs needs packages rvg and gdtools.

If you need to install them from source, you will need a cpp coompiler.** If have no idea what it means :

• you’re using R for Windows, install Rtools
• you’re using R for Mac, install Xcode
• you’re using R for Linux, you should manage on your own!

### Something screwed up

#### Could not find build tools

If you get an error during this step saying Error: Could not find build tools necessary to build XXX, you are probably installing the package from source (and rebuilding also rvg or gdtools), best advice is to read again that part :).

#### rJava hell

Common errors are:

• JAVA_HOME cannot be determined from the Registry
Loading required package: rJava
library(rJava)
call: fun(libname, pkgname)
error: JAVA_HOME cannot be determined from the Registry
• unable to load shared object […] rJava.dll
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object '[...]/rJava/libs/x64/rJava.dll':
LoadLibrary failure:  %1 is not a valid Win32 application.

Error: package/namespace load failed for 'rJava'

Most of the time, it comes from a bad java installation on your Windows machine:

• you are running R 64 bits but you have installed java 32 bits
• you are running R 32 bits but you have installed java 64 bits

Solution is to install the java version corresponding to your R version. I found that post very usefull:

I have a Windows 64 bits, I installed java 32 bits and java 64 bits. When I install ReporteRs, I don’t meet any trouble.

If you are on a Windows machine and (for any reason) you can only have one java version (32 or 64 bits), install the package with the following option :


install.packages("ReporteRs", INSTALL_opts = "--no-multiarch")

install_github("davidgohel/ReporteRs", args = "--no-multiarch")

Some solutions on Stackoverflow involve to set environment variable JAVA_HOME. I never had to use that but it seems a valid solution for some configurations.

If you are on a mac, the most common issue with java is a newer version of java messed your setup.

From a terminal, run:

R CMD javareconf

Then reintall the package.

### font config error: unable to match font pattern

This probably means you are running R for mac OS. Package gdtools need cairo to be correctly installed. From a terminal, run:

brew update
brew reinsall cairo

Then from R, run:

devtools::install_github("davidgohel/gdtools")
devtools::install_github("davidgohel/rvg")
devtools::install_github("davidgohel/ReporteRs")

## Word: replace only a word in a paragraph

That is not a feature but this can be achieved by formating your text with pot objects.


library(ReporteRs)

# various text formatting properties we will use----
base_text_prop <- textProperties(font.family = "Arial")
bold_text_prop <- chprop( base_text_prop,
font.weight = "bold", color = "red")
italic_text_prop <- chprop( base_text_prop, font.style = "italic")

# concatenate chunk of formatted text -----
your_pot <- pot("This is a pot ", format = base_text_prop) +

pot( "with italic text", format = italic_text_prop) +

pot( " and red bold", format = bold_text_prop)

# replace whole paragraph by the previous object -----
doc <- docx( title = "My example",
template = file.path( system.file(package = "ReporteRs"),
"templates/bookmark_example.docx") )

doc <- addParagraph(doc, your_pot, bookmark = "REVIEWER" )
target_file <- "replace_and_pot.docx" # file to produce

writeDoc(doc, target_file)

## PowerPoint: offx, offy, width and height

You may want to arrange plot, tables or paragraphs freely on a slide - without mapping content to a layout defined in the slide master layouts.

In this case, usage of some parameters is becoming mandatory. You will need to specify:

• width and height that are the shape dimensions
• arguments offx and offy that are the shape positions (left and top positions)

## PowerPoint and par.properties

Usually there is no need for managing par.properties when adding content in a slide: i.e. graphics and tables cannot be associated with center or padding properties. Paragraphs can.

When formatting properties of paragraphs don’t inherit from the template (when adding a pot or a set_of_paragraphs), par.properties can be used to specify alignment of paragraphs.


library(ReporteRs)

doc <- pptx( )
doc <- addSlide( doc, slide.layout = "Title and Content" )

doc <- addParagraph( par.properties = parCenter(),
doc = doc, value = pot("this is a pot", textBold(color = "red")),
offx = 3, offy = 5, width = 2, height = 1 )

target_file <- "par_and_par_props.pptx" # file to produce

writeDoc(doc, target_file)