R console: When I call source("file_of_functions.R",echo=TRUE)
, all source file expressions, including comments, print to console.
Knit HTML: When I put source("file_of_functions.R",echo=TRUE)
within a chunk and knit to html, the same output prints except for comments.
For clarity of my code and report, I would like the comments of the source file to be included in the html report.
Any suggestions?
Basic example: Save the following as f.R:
# function to add a number to itself
f <- function(x) x+x
f(2)
In console, the call source("f.R",echo=TRUE)
prints:
#function to add a number to itself > f <- function(x) x+x > f(2) > [1] 4
When knitting to html, the call
```{r}
source("f.R",echo=TRUE)
```
yields the same output but without the comment.
source(..., keep.source = TRUE
) work? – rawr Jul 1 '15 at 0:13