Search code examples
tabsincluder-markdownparameterizedchunks

Exclude tabs Rmarkdown based on parameters


I know I can include exclude r code chunks using parameters in Rmarkdown. http://rmarkdown.rstudio.com/developer_parameterized_reports.html

However how can I exclude or include tabs based on the value of a parameter. Where a tab is indicated as:

## Header {.tabset}

### Tab 1
content Tab 1

### Tab 2
content Tab 2

##

I'm looking for something like

    ## Header {.tabset}

    ### Tab 1
    content Tab 1

    ifelse(param == False) {
    ### Tab 2
    content Tab 2
    }
    ##

Update

I have some troubles with the answer by StatnMap. Using this code, in the first chunk the HTML after the R chunk is still shown as is the R chunk itself. I could fix this by using a separate eval = FALSE for the R chunk, but I would rather restrict myself to a single parameter in a single chunk. Thus, to only set eval = FALSE in the asis chunk.

## HEADER {.tabset .tabset-pills} 
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

``` {asis, echo = TRUE, eval = FALSE}
### TEST1
```{r echo=FALSE, warning=FALSE}
library(dplyr)
summary(cars)
```
You can also embed plots, for example:
```

### TEST2
```{r, pressure, echo=FALSE}
plot(pressure)
```

Solution

  • You can include your markdown syntax in a asis chunk:

    ```{asis, echo=TRUE, eval=param}
    ### Tab 2
    content Tab 2
    ```