In: Statistics and Probability
how do you insert R input into a word document?
you can use writedoc(Rdatafile, file = “Rdatafile.docx”) command to insert R input to word file
Let say you want to save your data in to file ‘Rdatafile.docx’ on your desktop (C:\Users\UserName\Desktop).
below R code will help, made appropriate modification as per you’re your data.
# Install the ‘WordR’ & ‘ReporteRs’ package
library(WordR)
library(ReporteRs)
library(ggplot2)
Output <- data Output # This is R input you want to insert in word file
Plt <- Plot(data) # This is R plot you want to insert in word file
Rdatafile <- docx()
Rdatafile <- addFlexTable(Rdatafile,FlexTable= Output )
Rdatafile <- addPageBreak(Rdatafile)
Rdatafile <- addParagra(Rdatafile, value = "", stylename= "Normal")
Rdatafile <- addPlot(Rdatafile, plt, height = 4)
writedoc(Rdatafile, file = “Rdatafile.docx”)