Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

global comment option for R markdown in knitr

Tags:

r

knitr

To change the leading characters for the output a knitr chunk in .Rmd has a comment option, like

```{r comment = ""}
1:100
```

Is there a way to set this globally, not separately for every chunk?

opts_knit$set(comment = "")

does not work and I cannot find it anywhere in the documentation.

like image 444
Mark Heckmann Avatar asked Jun 25 '12 13:06

Mark Heckmann


People also ask

How do you comment out in R Markdown?

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.

How do you use knitr in R Markdown?

There are two ways to render an R Markdown document into its final output format. If you are using RStudio, then the “Knit” button (Ctrl+Shift+K) will render the document and display a preview of it. Note that both methods use the same mechanism; RStudio's “Knit” button calls rmarkdown::render() under the hood.

How do I add a note in R Markdown?

On a new line, type: [//]: (This is my fuarking comment!)

What does knitr :: Opts_chunk set echo true mean?

The first code chunk: ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` is used to specify any global settings to be applied to the R Markdown script. The example sets all code chunks as “echo=TRUE”, meaning they will be included in the final rendered version.


1 Answers

Use opts_chunk$set() because that is a chunk option; opts_knit is for package options (sorry about the similar names which apparently confused you). See http://yihui.name/knitr/options

like image 168
Yihui Xie Avatar answered Oct 18 '22 18:10

Yihui Xie