Example: My R script is named \"code.R\". It produces a simple plot of y versus x. And looks like this in Rmarkdown.
````{r eval=FALSE}
## code in \"
Solution found on: http://yihui.name/knitr/demo/externalization/
Start your input.R script with the comment "## ---- input.R" (without the quotes)
Make an .Rmd script with the following code and Knit it. It will show the content of the input.R script in the resulting PDF.
---
output: pdf_document
---
```{r cache=FALSE, echo=FALSE}
knitr::read_chunk('input.R')
```
```{r input.R, eval=FALSE}
```