davidgohel / ReporteRs

Note that ReporteRs has been removed from CRAN the 16th of July 2018 and is not maintained anymore. please migrate to officer.
244 stars 44 forks source link

Use of magrittr makes document creation look cleaner #134

Closed rpruim closed 8 years ago

rpruim commented 8 years ago
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, ]), 
                    layout.properties= get.light.tableProperties())

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, 'files/gettingstarted/my_first_doc.docx' )

becomes

require(magrittr)
require( ggplot2 )
myggplot = qplot(Sepal.Length, Petal.Length, data = iris, color = Species, size = Petal.Width )

doc <- 
  docx(title = 'My document') %>%
  addTitle('First 5 lines of iris', level = 1) %>%
  addFlexTable(vanilla.table(iris[1:5, ]), 
                    layout.properties= get.light.tableProperties()) %>%
  addTitle( doc , 'ggplot2 example', level = 1) %>%
  addPlot(fun = print, x = myggplot) %>%
  addTitle('Text example', level = 1) %>%
  addParagraph('My tailor is rich.', stylename = 'Normal')

doc %>% writeDoc('files/gettingstarted/my_first_doc.docx')
davidgohel commented 8 years ago

thanks,

in the next doc update, I will make a mention to magrittr.