Search code examples
rreporters

Make a landscape table in a word document


I am using ReporteRs package in R to create a report. I have a table which has 13 columns and I would like it to go in a landscape orientation. Otherwise some columns will be cut down from the table. I am wondering whether it is possible to specify this in ReporteRs for a specific FlexTable object? All the other tables and texts come in portrait format. My apologies for not giving a reproducible example. Thank you in advance.


Solution

  • You can do it with addSection:

    library(ReporteRs)
    doc = docx()
    doc = addSection( doc, landscape = T ) 
    doc = addFlexTable( doc, FlexTable( mtcars) )
    doc = addSection( doc, landscape = F ) 
    writeDoc( doc, "test.docx")
    

    Another solution would be to create an empty Word document with landscape orientation and then to use it as a template:

    library(ReporteRs)
    doc = docx(template = "your_landscape_doc.docx")
    doc = addFlexTable( doc, FlexTable( mtcars) )
    writeDoc( doc, "test.docx")