小编Jon*_*man的帖子

R,knitr和source函数:如何保留html报告的源文件注释

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)打印:

#function to add a number to itself
> f <- function(x) x+x
> f(2)
> [1] 4
Run Code Online (Sandbox Code Playgroud)

编织到html时,通话

```{r}
source("f.R",echo=TRUE)
```
Run Code Online (Sandbox Code Playgroud)

产生相同的输出,但没有评论.

r knitr

8
推荐指数
2
解决办法
1535
查看次数

标签 统计

knitr ×1

r ×1