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。它看起來是一個很好的選擇。我要去嘗試一下。 –