19.1 Office Software and R

R users are mainly Latex users, so Latex integration is superior to Word integration. However there are tricks to improve your workflow when working with R and Word:

  • Crosstables: export with write.csv()
write.csv(mytable, file = ".crosstab.csv")

You could open this file with Excel to add design and include this as a dynamic table within Word.

  • Regression tables: Even better: htmlreg() from library(texreg)
install.packages("texreg")
library(texreg)
fit1 <- lm(Fertility ~ Catholic, data = swiss)
fit2 <- lm(Fertility ~ Education, data = swiss)
htmlreg(list(fit1, fit2), booktabs = FALSE, dcolumn= FALSE,file = "./file.doc") # fake doc file
htmlreg(list(fit1, fit2), booktabs = FALSE, dcolumn= FALSE,file = "./file.html") # html

The latter option exploits Words very good compatibility with HTML. You can open the html File with your browser and copy paste it to Word.

  • Summary statistics: stargazer
    • Stargazer is probably the way to go generally.
library(stargazer)
stargazer(swiss, type = "html", out = "./summaryswiss.html")
fit1 <- lm(Fertility ~ Catholic, data = swiss)
fit2 <- lm(Fertility ~ Education, data = swiss)
stargazer(fit1, fit2, type = "html", out = "./regressionswiss.html")
# Change type if you want!

Again we exploit that Word can nicely read in HTML files (copy paste from your browser). You can also do this for regression tables. Check http://www.princeton.edu/~otorres/NiceOutputR.pdf for an overview of this excellent package!