Skip to content

Instantly share code, notes, and snippets.

@murattasdemir
Last active October 23, 2018 17:28
Show Gist options
  • Save murattasdemir/4c411be44a7b0a94212a975469082079 to your computer and use it in GitHub Desktop.
Save murattasdemir/4c411be44a7b0a94212a975469082079 to your computer and use it in GitHub Desktop.
Alternative ways of generating tables and saving as an image file to import into a Word document
# Function to create png tables from data
# By Michael Yan.
table.png <- function(obj, name) {
first <- name
name <- paste(name,".tex",sep="")
sink(file=name)
cat('
\\documentclass{report}
\\usepackage[paperwidth=5.5in,paperheight=7in,noheadfoot,margin=0in]{geometry}
\\begin{document}\\pagestyle{empty}
')
print(xtable::xtable(obj))
cat('
\\end{document}
')
sink()
tools::texi2dvi(file=name)
cmd <- paste("dvipng -T tight -D 600", shQuote(paste(first,".dvi",sep="")))
invisible(system(cmd))
cleaner <- c(".tex",".aux",".log",".dvi")
invisible(file.remove(paste(first,cleaner,sep="")))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment