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
How to Delete Rows Where All the Columns Are Zero
Multiplying All Columns in Dataframe by Single Column
How to Fix Spaces in Column Names of a Data.Frame (Remove Spaces, Inject Dots)
Numbering Rows Within Groups in a Data Frame
How to Prevent Ifelse() from Turning Date Objects into Numeric Objects
Determine Path of the Executing Script
Data.Table Objects Assigned With := from Within Function Not Printed
Specify Custom Date Format For Colclasses Argument in Read.Table/Read.Csv
Conditionally Replace Values of Subset of Rows With Column Name in R Using Only Tidy
How to Find the Difference in Value in Every Two Consecutive Rows in R
Removing Space Between Numeric Values in R
How to Deal With "Package 'Xxx' Is Not Available (For R Version X.Y.Z)" Warning
Subset Rows Corresponding to Max Value by Group Using Data.Table
How to Save a Plot as Image on the Disk