在写论文时,我通常使用knitr嵌入我在R中生成的表格和绘图。所有这些对我来说都非常有效。然而,我的一些合著者并不热衷于这个工作流程,他们更愿意把与knitr的交互留给我,而专注于编写他们的部分,而不必费心编写R代码。他们也不希望安装R、RStudio和各种包。
那么,有没有一种方法可以排版包含嵌入式knitr块的LaTeX文档,而不必先运行R?换句话说,有没有一种方法可以在排版过程中简单地忽略块(或者用虚拟的表格/图代替它们)?
发布于 2014-01-22 10:41:23
更新:修订的description here
这并没有回答确切的问题,但可能是用例。我最近遇到了一个类似的挑战:我想在一个.rnw文件中结合编写和分析,但我的合作者不想使用R/RStudio/GitHub/LaTeX。
所以我决定通过Dropbox与他们共享我的git repo的一个子文件夹。该文件夹包含三个.docx文件:introduction.docx、methods.docx和discussion.docx (我在.rnw文件中编写结果部分)。唯一的问题是他们在编写时必须使用一些非常基本的LaTeX,例如,\subsection{heading}表示标题,\cite{key}表示引用,引号‘’,转义\%,\$和\&。
回到.rnw文件,我将.docx文件转换为.txt
system("textutil -convert txt introduction.docx")
然后将文件扩展名从.txt重命名为.tex
file.rename("introduction.txt", "introduction.tex")
然后,在R代码块之外,我使用以下命令调用.tex文件:
\input{introduction}
我在GitHub上发布了一个small example。
\documentclass{article}
\makeatletter
\renewcommand{\@biblabel}[1]{\quad#1.}
\makeatother
\date{}
\bibliographystyle{plain}
\begin{document}
\begin{flushleft}
{\Large
\textbf{My Title}
}
\end{flushleft}
\section{Introduction}
% do not write in this section...let collaborators write in introduction.docx
<<intro, include=FALSE>>=
# assumes wd set to root folder collaborate
# convert docx to txt
system("textutil -convert txt introduction.docx")
# rename txt to tex
file.rename("introduction.txt", "introduction.tex")
@
% pull in introduction.tex
\input{introduction}
\section{Methods}
<<methods, include=FALSE>>=
system("textutil -convert txt methods.docx")
file.rename("methods.txt", "methods.tex")
@
\input{methods}
\section{Results}
<<results>>=
dat <- data.frame(x=runif(30, 0, 30))
mean <- mean(dat$x, na.rm=TRUE)
@
The mean is \Sexpr{round(mean, 1)}.
\section{Discussion}
<<discussion, include=FALSE>>=
system("textutil -convert txt discussion.docx")
file.rename("discussion.txt", "discussion.tex")
@
\input{discussion}
\bibliography{example.bib}
\end{document}https://stackoverflow.com/questions/21094847
复制相似问题