R, knitr, and source function: How to preserve source file comments for html report

后端 未结 2 1494
攒了一身酷
攒了一身酷 2021-01-11 22:17

R console: When I call source(\"file_of_functions.R\",echo=TRUE), all source file expressions, including comments, print to console.

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-11 22:33

    I don't mean to post this as an answer, but I just want to point out the possibility that you can easily insert test.r into a code chunk using

    ```{r code=readLines('test.r')}
    ```
    

    Personally I think this is much nicer than using source(), e.g. you don't get the prompts > by default (you can if you want), and the R code will be syntax highlighted. Of course, your comments will be preserved.

提交回复
热议问题