No great options to comment out text in R Markdown #4
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
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?
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):
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
This is the most popular answer (by far) on SO:
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.
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 :-)