R控制台:当我调用时source("file_of_functions.R",echo=TRUE),所有源文件表达式(包括注释)都打印到控制台.
编织HTML:当我放入source("file_of_functions.R",echo=TRUE)一个块并编织到html时,除了注释之外,打印相同的输出.
为了清楚我的代码和报告,我希望源文件的注释包含在html报告中.
有什么建议?
基本示例:将以下内容另存为fR:
# function to add a number to itself
f <- function(x) x+x
f(2)
Run Code Online (Sandbox Code Playgroud)
在控制台中,调用source("f.R",echo=TRUE)打印:
Run Code Online (Sandbox Code Playgroud)#function to add a number to itself > f <- function(x) x+x > f(2) > [1] 4
编织到html时,通话
```{r}
source("f.R",echo=TRUE)
```
Run Code Online (Sandbox Code Playgroud)
产生相同的输出,但没有评论.