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?
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).
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 ...
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 .
The shortcut to interrupt a running process in R depends on the R software and the operating system you are using. However, if you are using RStudio on a Windows computer, you can usually use Esc to stop a currently executing R script. Then, we can press Esc to interrupt the loop.
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.
Might also be interesting for you to know that you can use:
{r echo=FALSE, results='hide',message=FALSE} a<-as.numeric(rnorm(100)) hist(a, breaks=24)
to exclude all the commands you give, all the results it spits out and all message info being spit out by R (eg. after library(ggplot) or something)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With