How to Show Code But Hide Output in Rmarkdown

How to show code but hide output in RMarkdown?

As @ J_F answered in the comments, using {r echo = T, results = 'hide'}.

I wanted to expand on their answer - there are great resources you can access to determine all possible options for your chunk and output display - I keep a printed copy at my desk!

You can find them either on the RStudio Website under Cheatsheets (look for the R Markdown cheatsheet and R Markdown Reference Guide) or, in RStudio, navigate to the "Help" tab, choose "Cheatsheets", and look for the same documents there.

Finally to set default chunk options, you can run (in your first chunk) something like the following code if you want most chunks to have the same behavior:

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = T,
results = "hide")
```

Later, you can modify the behavior of individual chunks like this, which will replace the default value for just the results option.

```{r analysis, results="markup"}
# code here
```

How to show and run code but don't print results in Rmarkdown knitr

Take a look here.

If you want to show the code, use echo=TRUE.

Hiding the R code in Rmarkdown/knit and just showing the results

Sure, just do

```{r someVar, echo=FALSE}
someVariable
```

to show some (previously computed) variable someVariable. Or run code that prints etc pp.

So for plotting, I have eg

### Impact of choice of ....
```{r somePlot, echo=FALSE}
plotResults(Res, Grid, "some text", "some more text")
```

where the plotting function plotResults is from a local package.

How to hide code in RMarkdown, with option to see it

This has been made much easier with the rmarkdown package, which did not exist three years ago. Basically you just turn on "code folding": https://bookdown.org/yihui/rmarkdown/html-document.html#code-folding. You no longer have to write any JavaScript.

E.g.

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

Also see https://bookdown.org/yihui/rmarkdown-cookbook/fold-show.html for more control over which code blocks to be fold or unfold.

How to suppress the code but have the plots displayed in R markdown?

Use echo=FALSE, neither results="hide" nor include=FALSE in your chunk options (I think the latter is your real problem). (As @markdly comments below, that means {r, echo=FALSE, fig.width=8, fig.height=6} are the options you want to use.)

toggle show/hide code in RMarkdown

From the answer to a similar question by Yihue -this functionality has now been added as code folding. See more at
http://rmarkdown.rstudio.com/html_document_format.html



Related Topics



Leave a reply



Submit