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

Mark picture Mark · Oct 26, 2012 · Viewed 118.1k times · Source

In my R Markdown documents, I sometimes want to just generate a report without showing the actual code (specially when I send it to my boss). How can I hide the R code and just show the graph and results?

For example:

---
output: html_document
---

```{r fig.width=16, fig.height=6}
plot(cars)
```

This shows both the commands and the plot. How can I remove the commands from my HTML report?

Answer

Dirk Eddelbuettel picture Dirk Eddelbuettel · Oct 26, 2012

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.