Install ReporteRs from cran with the following command:
Install developement version of ReporteRs from Github with the following command:
ReporteRs needs packages
This requires a cpp coompiler. If have no idea what it means :
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 :).
Common errors are:
Loading required package: rJava library(rJava) Error : .onLoad failed in loadNamespace() for ‘rJava’, details: call: fun(libname, pkgname) error: JAVA_HOME cannot be determined from the Registry
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:
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.
That is not a feature but this can be achieved by formating your text with
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)
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:
heightthat are the shape dimensions
offythat are the shape positions (left and top positions)
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
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)