Create a PDF table

后端 未结 5 1122
庸人自扰
庸人自扰 2020-11-29 20:40

Is there a way to produce a PDF of a table from R in the same way you produce a plot (ie with pdf() or ggsave())? I realize there are ways with other programs (using sweave

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 21:21

    I recently wanted to do this but didn't like the output format of grideExtra or textplot so I wrote this function to do it in latex. It's a bit of a hack job and there are better ways with sweave or knitr, but you might find it useful to modify for your purposes:

    createPDF <- function(xx, name=deparse(substitute(xx))){
      require(xtable)
      tt <- print(xtable(xx), type='latex')
      texfile <- paste0('./reports/', name, '.tex')
      cat(
        '\\documentclass[12pt]{report}
    \\usepackage[landscape]{geometry}
    \\date{}
    \\begin{document}', tt, '\\end{document}', sep='', 
        file=texfile
      )
      ## pdflatex from texlive package for linux converts .tex to .pdf
      system(paste0('pdflatex ', '-output-directory ./reports ', texfile))
    }
    

提交回复
热议问题