I am trying to comment out a section of code in my RMarkdown. I know that I can use the <!-- -->
syntax to add comments, but these comments still appear in the rendered HTML (although hidden). Is there a way to create real comments that are ignored during rendering and don't appear in the exported document source code?
CodePudding user response:
You could specify with echo
to code lines to show in your output like this:
---
date: "2022-12-13"
output: html_document
---
```{r echo=2:4}
# This comment should not be shown
rnorm(3)
# But keep this comment in output html
```
Output:
As you can see it doesn't show the first comment.
CodePudding user response:
You can wrap everything in ~~~{=comment}
... ~~~
to get it ignored:
Normal text
~~~{=comment}
this will be ignored
This, too!
~~~
No longer in a comment.