Last active
October 23, 2018 17:28
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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