Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RMarkdown button to show or hide code

Tags:

markdown

r

I am often writing markdown documents that get read by both technical people and executives.

In that sense, I was wondering if its possible to create a button in the HTML that would hide or show the code chunks in the final output?

Currently, I am creating two seperate files, which I think is a less elegant solution.

Anyone?

like image 903
Prometheus Avatar asked May 03 '17 07:05

Prometheus


People also ask

How do I embed code into R Markdown?

You can insert an R code chunk either using the RStudio toolbar (the Insert button) or the keyboard shortcut Ctrl + Alt + I ( Cmd + Option + I on macOS).

How do you display output but hide code in R Markdown?

Chunk options The initial line in a code chunk may include various options. For example, echo=FALSE indicates that the code will not be shown in the final document (though any results/output would still be displayed). You use results="hide" to hide the results/output (but here the code would still be displayed).

How do I hide code markdown?

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 ...

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 .


1 Answers

@docendo discimus provided a link that answers the OP question. I'm including the code here for posterity purposes.

---
title: "test"
output: 
  html_document:
    code_folding: hide
---

Which produces the code folding button: enter image description here

like image 113
jordan Avatar answered Sep 22 '22 05:09

jordan