rmarkdown::render 编译 LaTeX 文档

rmarkdown::render to compile LaTeX documents

This example LaTeX file 使用 Rstudio、TexShop 和 pdflatex example.tex 对我来说编译得很好。但是 rmarkdown::render 不起作用。

> rmarkdown::render("example.tex", output_format = "pdf_document")
/usr/local/bin/pandoc +RTS -K512m -RTS example.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output example.pdf --template /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rmarkdown/rmd/latex/default.tex --highlight-style tango --latex-engine /Library/TeX/texbin/pdflatex --variable graphics=yes --variable 'geometry:margin=1in' 
! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.88 \documentclass

pandoc: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
> 

有没有办法告诉 rmarkdown 我是从 LaTeX 文档开始的?我正在使用

没关系。 tools::texi2pdf("example.tex") 从命令行使用 Rstudio 和 R 为我工作。 The R GUI failed in error, though.