15/04/2016
Reporting automation from R
MS formats are still ubiquitous in corporate environments
Formats and complex layouts are strong requirements
Document updates and graphical annotations are time consuming
Deploiement must be easy
An R API for creating
library(ReporteRs)
## Loading required package: ReporteRsjars
library(magrittr) library(ggplot2) myplot <- ggplot(data = mtcars, aes(x = wt, y = qsec, color = drat)) + geom_point() my_ft <- vanilla.table(mtcars)
myplot
docx() %>% addTitle("Tabular example") %>% addFlexTable( my_ft ) %>% addTitle("Graphic example") %>% addPlot(fun = print, x = myplot, vector.graphic = TRUE) %>% writeDoc("docs/first_.docx")
It produces this document.
pptx() %>% addSlide("Title and Content") %>% addTitle("Tabular example") %>% addFlexTable( my_ft ) %>% addSlide("Title and Content") %>% addTitle("Graphic example") %>% addPlot(fun = print, x = myplot) %>% writeDoc("docs/first_.pptx")
It produces this document.
addFlexTable | addPlot |
addParagraph | addTitle |
addTOC | addBreakPage |
addSlide | addSection |
addImage | addMardown |
… | … |
rtable
.## Source: local data frame [12 x 6] ## Groups: Status, Gender [?] ## ## Status Gender Ulceration n mean sd ## (chr) (chr) (chr) (int) (dbl) (dbl) ## 1 Alive Female Absent 68 1.693 2.004 ## 2 Alive Female Present 23 2.972 2.593 ## 3 Alive Male Absent 24 1.468 1.719 ## 4 Alive Male Present 19 4.319 2.423 ## 5 Melanoma Female Absent 8 2.139 1.184 ## 6 Melanoma Female Present 20 4.724 4.128 ## 7 Melanoma Male Absent 8 3.266 4.681 ## 8 Melanoma Male Present 21 5.143 2.862 ## 9 Non-melanoma Female Absent 3 1.667 1.141 ## 10 Non-melanoma Female Present 4 3.302 3.713 ## 11 Non-melanoma Male Absent 4 2.420 2.499 ## 12 Non-melanoma Male Present 3 8.053 4.019
my_flextable = FlexTable( data ) %>% spanFlexTableRows(j = 1, runs = data$Status) %>% spanFlexTableRows(j = 2, runs = data$Gender) %>% addHeaderRow( value = c("Group by", "Statistics"), colspan = c(3, 3), first = T ) %>% setFlexTableWidths(widths = c(1.5, 1.5, 1.5, .75, .75, .75))
my_flextable[to = "header"] = textBold(font.size=12) my_flextable[to = "header"] = parCenter(padding=2) my_flextable[] = textNormal(font.size=11) my_flextable[data$mean < 2, "mean" ] = textItalic(color = "gray", font.size=11) my_flextable[data$mean > 3, "mean" ] = textBold(color = "red", font.size=11) my_flextable[] = parCenter(padding=2)
my_flextable[data$sd > 2, "sd", text.properties = textProperties( vertical.align = "superscript") ] = "*" my_flextable <- addFooterRow(my_flextable, value = "*", colspan = 6, text.properties = textProperties( vertical.align = "superscript") ) my_flextable[1, 1, to = "footer"] = "standard deviation is > 2"
addPlot
vector.graphics=TRUE
pptx() %>% addSlide("Title and Content") %>% addPlot(fun = print, x = myplot, vector.graphic = TRUE) %>% writeDoc("docs/evg_.pptx") docx() %>% addPlot(fun = print, x = myplot, vector.graphic = TRUE) %>% writeDoc("docs/evg_.docx")
install.packages(c( "ReporteRs", "rtable") )
rtable
is complementing ReporteRs
for tabular reporting.
Most common issues :
stackoverflow and tag reporters
: http://stackoverflow.com/questions/tagged/reporters
google-groups: https://groups.google.com/forum/#!forum/reporters-package
Creating PowerPoint presentations
http://www.sthda.com/english/wiki/create-and-format-powerpoint-documents-from-r-software
Creating Word documents