How to show code but hide output in RMarkdown?

前端 未结 6 558
生来不讨喜
生来不讨喜 2020-12-13 01:58

I want my html file to show the code, but not the output of this chunk:

```{r echo=True, include=FALSE}
fun <- function(b)
    {
    for(a in b)
        {         


        
6条回答
  •  情歌与酒
    2020-12-13 02:23

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

提交回复
热议问题