No great options to comment out text in R Markdown #4
When writing in R Markdown format I often would like to comment out one or more lines of text (for example to quickly test variations on sentences or paragraphs) in a way that these comments do not show in the generated HTML file.
The R Markdown Cookbook only mentions HTML comment syntax
<!-- your comment --> which does not stop the comment from remaining in the generated HTML file.
Best solutions, as far as I know:
Additional YAML blocks
Add a YAML block with commented out lines (baptiste's suggestion):
Some text in the document. --- # commented out text # and such ---
This works fine, it is just slightly verbose to use.
But it is the only option that works without any issues.
Abuse the markdown link labels syntax
Some text in the document. [//]: # (commented out text) [//]: # (another comment)
According to other answers/comments, this sort of comment line should always have a blank line before it to be proper.
The drawback for Rmd appears as soon as we have more than one such comment line; knitr spits out a very visible warning in the standard output:
[WARNING] Duplicate link reference '[//]' at ... line ....
The only(?) way to avoid those warnings is to differentiate the link labels, but that quickly becomes tedious.
Some text in the document. [//1]: # (commented out text) [//2]: # (another comment, now without a knitr warning)
If you know of a less verbose method than adding YAML blocks, or an easier to circumvent the knitr warnings, I would love to learn :-)
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?