Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Hashes in R Output from R Markdown and Knitr

I am using RStudio to write my R Markdown files. How can I remove the hashes (##) in the final HTML output file that are displayed before the code output?

As an example:

--- output: html_document ---  ```{r} head(cars) ``` 

enter image description here

like image 557
mchangun Avatar asked Feb 26 '13 04:02

mchangun


People also ask

How do I hide code in R Markdown output?

Hide source code: ```{r, echo=FALSE} 1 + 1 ``` Hide text output (you can also use `results = FALSE`): ```{r, results='hide'} print("You will not see the text output.") ``` Hide messages: ```{r, message=FALSE} message("You will not see the message.") ``` Hide warning messages: ```{r, warning=FALSE} # this will generate ...

What does ## do in R Markdown?

For example, # Say Hello to markdown . A single hashtag creates a first level header. Two hashtags, ## , creates a second level header, and so on. italicized and bold text - Surround italicized text with asterisks, like this *without realizing it* .

How do I show output in R Markdown?

If you prefer to use the console by default for all your R Markdown documents (restoring the behavior in previous versions of RStudio), you can make Chunk Output in Console the default: Tools -> Options -> R Markdown -> Show output inline for all R Markdown documents .

What is results ASIS?

You can use the knitr chunk option results = "asis" if you are happy to add two or more spaces at the end of the line. That is, instead of "hello\n" , you need to write "hello \n" to trigger the line break. Example R Markdown code: --- output: html_document --- ```{r} myfun <- function() { cat("hello! \


1 Answers

You can include in your chunk options something like

comment=NA # to remove all hashes 

or

comment='%' # to use a different character 

More help on knitr available from here: http://yihui.name/knitr/options

If you are using R Markdown as you mentioned, your chunk could look like this:

```{r comment=NA} summary(cars) ``` 

If you want to change this globally, you can include a chunk in your document:

```{r include=FALSE} knitr::opts_chunk$set(comment = NA) ``` 
like image 91
Gary Weissman Avatar answered Sep 18 '22 21:09

Gary Weissman