Mic*_*ico 4 r knitr r-markdown
该建议在注释.Rmd文档中使用HTML注释<!-- comment here -->是不够的.我想评论一下我的文档中包含内联评估的部分:
I haven't defined `x` yet.
<!-- So when I say that `x` is `r x` in the text, I'd like to comment it out -->
Run Code Online (Sandbox Code Playgroud)
编织失败:
# |.................................................................| 100%
# inline R code fragments
#
#
#
#
# processing file: test.Rmd
# Quitting from lines 2-3 (test.Rmd)
# Error in eval(expr, envir, enclos) : object 'x' not found
# Calls: <Anonymous> ... in_dir -> inline_exec -> withVisible -> eval -> eval
# Execution halted
Run Code Online (Sandbox Code Playgroud)
一种选择是评论每个内联部分:
I haven't defined `x` yet.
So when I say that `x` is `r #x` in the text, I'd like to comment it out
Run Code Online (Sandbox Code Playgroud)
但是,如果我想用几个这样的内联计算来评论整个段落,那就会受到影响.是否有更规范的方式来做到这一点?
正如@NicE所说,knitr首先评估您的代码,特别是因为可能存在内联R代码评估或其他R变量相关文本,然后需要将其评估为markdown语法.例如,这包括在rmarkdown中:
Define if bold `r bold <- TRUE`
This text is `r ifelse(bold, "**bold**", "_italic_")`.
Run Code Online (Sandbox Code Playgroud)
得到:
定义是否加粗
此文本为粗体.
然后,我认为在不评估它们的情况下插入注释的唯一方法是将它们嵌入到eval=FALSE&echo=FALSE
```{r, eval=FALSE, echo=FALSE}
So when I say that `x` is `r x` in the text, I'd like to comment it out
```
Run Code Online (Sandbox Code Playgroud)