1
votes

I am new to Sweave/Tex and would like to keep my R code out of the Sweave file as much as possible. Ideally, I would like to reference my R files within Sweave's .Rnw file and then have Sweave read it directly.

An example might be something like this:

    \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}

Thanks

1

1 Answers

7
votes

That's a "yes" because the snippet between <<>>= and @ is for R code, so you can use source().

But just because you can does not mean you should. There are templating solutions as e.g. the brew package, or you could try the newest kid on the block, the knitr package.