I use ProjectTemplate and Knitr to produce reports. Most of the analysis is stored in the src directory, whilst the report contains the presentation R markdown.
I
You may try this:
In the main body:
```{r runanalysis, code=readLines('../src/rf-model-caret.R'), echo=FALSE, eval=TRUE} ```
In the appendix:
```{r runanalysis, code=readLines('../src/rf-model-caret.R'), echo=TRUE, eval=FALSE} ```