可以Sweave读取R文件吗?

Boo*_*aka 1 latex r sweave

我是Sweave/Tex的新手,并且希望尽可能地将我的R代码保留在Sweave文件之外.理想情况下,我想在Sweave的.Rnw文件中引用我的R文件,然后让Sweave直接读取它.

一个例子可能是这样的:

    \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}
Run Code Online (Sandbox Code Playgroud)

谢谢

Dir*_*tel 7

这是一个"是",因为之间的片段<<>>=,并@可以使用R代码,这样你就可以使用source().

但仅仅因为你并不意味着你应该这样做.有模板解决方案,例如brew包,或者你可以试试最新的小块,knitr包.

  • 特别是,knitr的功能[代码外化](http://yihui.github.com/knitr/demo/externalization/) (4认同)