129
votes

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.

4
Was initially closed as duplicate; re-opening since Rmarkdown can potentially provide alternative options not supported by markdown.baptiste

4 Answers

181
votes

I think you should be able to use regular html comments:

<!-- regular html comment --> 

Does this work for you?

33
votes

Extra yaml blocks can be used anywhere inside the document, and commented out with #

---
title: "Untitled"
output: html_document
---

No comment.

---
# here's a comment
# ```{r}
# x = pi
# ```
--- 

Note however that this does not prevent knitr from evaluating inline r code.

20
votes

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.

0
votes

You can always turn off code by putting it within an if(F){} statement.