In an R Markdown (.Rmd) file, how do you comment out unused text? I'm not referring to the text in the R code chunk, but the general texts, like % in LaTex for example.
- 2Was initially closed as duplicate; re-opening since Rmarkdown can potentially provide alternative options not supported by markdown.baptiste– baptiste2017-10-23 01:42:57 +00:00Commented Oct 23, 2017 at 1:42
- This question is widely answered here: stackoverflow.com/questions/4823468/comments-in-markdownChema_arguez– Chema_arguez2023-01-30 09:01:04 +00:00Commented Jan 30, 2023 at 9:01
Add a comment |
5 Answers
I think you should be able to use regular html comments:
<!-- regular html comment --> Does this work for you?
2 Comments
Brian D
oddly, inline r code within those html comments tries to evaluate. e.g.,
<-- Some text with `r mean(x)` inline code --> can result in 'blah not Found' errors on Knit due to the inline code being unexpectedly evaluated.randy
I think I remember seeing Yihui Xie mention that having knitr recognize the comment characters would be too difficult because knitr is not responsible for rendering the document into html or pdf. I think the HTML comment characters are only dealt with by pandoc/rmarkdown after knitting.
After drag the lines you want to make comment, press SHIFT+CMD+C (macOS), SHIFT+CTRL+C (Windows). This is the shortcut of R Markdown editor (R Studio) to comment out.
5 Comments
HelloGoodbye
I'm running Windows 10, and for me it was also Ctrl+Shift+C. Thanks!
z0nam
@EvanRosica, HelloGoodbye, Thank you for your information, I edited my answer to add windows shortcut explicitly.
Stephan Kolassa
This may work for people who use RStudio, but not for those who write Rmarkdown code with other editors or IDEs - for instance, I use Notepad++, and this shortcut of course does not help there.
Amy M
OP has specified in the body text of an R markdown document rather than a code chunk. Adding the hash symbol in body text will result in the text being formatted as a title.
Amy M
Had put a comment here about this being specific to code chunks, but just tested it in RStudio and it seems it does add HTML comment marks when applied to body text. It might be worth editing this answer to clarify that is the case.
We can use
# Converted R Markdown code chunk in .Rmd file `r ''````{r stream, eval=FALSE} strm <- FastqStreamer("a.fastq.gz") repeat { fq <- yield(strm) if (length(fq) == 0) break ## process chunk } This is found from a https://github.com/rstudio/rmarkdown-book/blob/main/03-documents.Rmd bookdown which is used we want a code block to not execute while knitting.
Does it solves your problem??? if you have any questions please let me know.