KnitR:是否有将 tex 文件编译为 PDF 的命令?

Fro*_*got 6 latex r pandoc knitr

谁能告诉我如何使用 R 中的 Knitr 命令将 tex 文件编译为 pdf?

我正在为我的工作自动化一个报告创建过程,并且有一个特定的报告类型我需要在其中编织一个 tex 文件,这是通过以下方式完成的:

knitr::knit('\somedirectory..')
Run Code Online (Sandbox Code Playgroud)

然后,出于“正则表达式”的原因,我使用 shell 命令执行 Python 脚本。

在这一点上,我留下了正确格式的 tex 文件,但无法弄清楚如何执行从 R 中创建 PDF 的最后一步。

整个过程需要自动化,因此不幸的是,无法选择加载 TeXmaker 等。

我在这篇文章中找到的最接近答案的内容是: Is it possible to compile .tex files to PDF with 'pandoc'?

但是,我对直接使用 pandoc 一点也不熟悉。这些 pandoc 命令可以以某种方式在 R 中执行吗?

非常感谢提前提供的任何帮助。

lmo*_*lmo 4

在包中,您将找到一个称为 的包装器的tools函数。如果您安装了所有正确的应用程序等,这将从 .tex 文件构建 pdf。texi2pdftexi2dvi

因此,假设您将以下文本复制到名为 myTexFile.tex 的文件中,并将该文件放入您的工作目录中,

texi2pdf("myTexFile.tex")
Run Code Online (Sandbox Code Playgroud)

将编译一个pdf。

Latex 复制到文件

\documentclass{article}

\begin{document}


\title{My Article}
\author{somebody\\
        some institution\\
        some place}

\date{\today}
\maketitle

\begin{abstract}
Here is an exciting abstract. Look at all the important stuff in my paper and publish it immediately.
\end{abstract}

\section{Introduction}
This is a longer set of reasons why this paper is so important.

\section{Data}
Here is a description of my amazing dataset. No one else has ever had access to this in the history of civilazation.

\subsection{Main Data}
Some more stuff about it.

\end{document}
Run Code Online (Sandbox Code Playgroud)