1
我是Sweave/Tex的新手,希望尽可能将我的R代码保留在Sweave文件之外。理想情况下,我想在Sweave的.Rnw文件中引用我的R文件,然后让Sweave直接读取它。可以Sweave读R文件吗?
一个例子可能是这样的:
\begin{document}
\title{Project}
\author{Author}
\date {\today}
<<>>=
**Reference to file: projectcode.R**
@
\begin{figure}[H]
<<fig=TRUE,echo=FALSE,png=TRUE,pdf=FALSE,eps=FALSE>>=
ggplot(df, aes(x, y)) + geom_line()
@
\end{figure}
\end{document}
感谢
特别是knitr的功能[code externalization](http://yihui.github.com/knitr/demo/externalization/) – baptiste
所以这听起来像我不是唯一一个想把R代码放在外面的人的Rnw文件:)(感谢您的链接,baptiste) –
Yihui - 感谢您的建筑knitr。它看起来是一个很好的选择。我要去尝试一下。 –